From f3b5cc32fa4e617825b2f76914599f1cb21defee Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 14 Nov 2017 00:37:45 +0100 Subject: [PATCH] Fix recently introduced crash in ClippingBoxTestCase Commit fc7f20c4191d31032b40b3a43c2c820e0cebecb0 did fix a memory leak in this test case, but at the price of introducing a crash due to deleting the same pointer twice. The real fix would be to change the code here to avoid returning a pointer which sometimes needs to be deleted and sometimes must not, but for now just add a crude check to avoid crashing. --- tests/graphics/clippingbox.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/graphics/clippingbox.cpp b/tests/graphics/clippingbox.cpp index 832105609b..6074b00e3c 100644 --- a/tests/graphics/clippingbox.cpp +++ b/tests/graphics/clippingbox.cpp @@ -1200,14 +1200,15 @@ void ClippingBoxTestCaseDCBase::OneDevRegionNonRect() // Draw image with reference triangle. wxBitmap bmpRef(s_dcSize); - wxMemoryDC* memDC = new wxMemoryDC(bmpRef); - wxDC* dcRef = GetDC(memDC); + wxMemoryDC memDC(bmpRef); + wxDC* dcRef = GetDC(&memDC); dcRef->SetBackground(wxBrush(s_bgColour, wxBRUSHSTYLE_SOLID)); dcRef->Clear(); dcRef->SetBrush(wxBrush(s_fgColour, wxBRUSHSTYLE_SOLID)); dcRef->SetPen(wxPen(s_fgColour)); dcRef->DrawPolygon(WXSIZEOF(poly), poly); - delete dcRef; + if ( dcRef != &memDC ) + delete dcRef; m_dc->SetDeviceOrigin(10, 15); m_dc->SetUserScale(0.5, 1.5); @@ -1229,7 +1230,6 @@ void ClippingBoxTestCaseDCBase::OneDevRegionNonRect() m_dc->DeviceToLogicalXRel(clipW), m_dc->DeviceToLogicalYRel(clipH), 1); CheckClipShape(bmpRef, 1); - delete memDC; } void ClippingBoxTestCaseDCBase::OneDevRegionAndReset()