From 1717db03738ac50277d68d8dd40b0e3dbbc4caa6 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 16 Mar 2016 00:02:31 +0100 Subject: [PATCH] Improved memory management in wxSVGFileDC. --- include/wx/dcsvg.h | 4 ++-- src/common/dcsvg.cpp | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/wx/dcsvg.h b/include/wx/dcsvg.h index 63ebb96463..79ac74e026 100644 --- a/include/wx/dcsvg.h +++ b/include/wx/dcsvg.h @@ -229,14 +229,14 @@ private: // their current values in wxDC. void DoStartNewGraphics(); - wxFileOutputStream *m_outfile; wxString m_filename; int m_sub_images; // number of png format images we have bool m_OK; bool m_graphics_changed; // set by Set{Brush,Pen}() int m_width, m_height; double m_dpi; - wxSVGBitmapHandler* m_bmp_handler; // class to handle bitmaps + wxScopedPtr m_outfile; + wxScopedPtr m_bmp_handler; // class to handle bitmaps // The clipping nesting level is incremented by every call to // SetClippingRegion() and reset when DestroyClippingRegion() is called. diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index a26754f2c9..209d35e54a 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -409,8 +409,8 @@ void wxSVGFileDCImpl::Init (const wxString &filename, int Width, int Height, ////////////////////code here - m_bmp_handler = NULL; - m_outfile = new wxFileOutputStream(filename); + m_bmp_handler.reset(); + m_outfile.reset(new wxFileOutputStream(filename)); m_OK = m_outfile->IsOk(); if (m_OK) { @@ -438,7 +438,6 @@ wxSVGFileDCImpl::~wxSVGFileDCImpl() s += wxS("\n\n"); write(s); - delete m_outfile; } void wxSVGFileDCImpl::DoGetSizeMM( int *width, int *height ) const @@ -956,8 +955,7 @@ void wxSVGFileDCImpl::SetBackgroundMode( int mode ) void wxSVGFileDCImpl::SetBitmapHandler(wxSVGBitmapHandler* handler) { - delete m_bmp_handler; - m_bmp_handler = handler; + m_bmp_handler.reset(handler); } void wxSVGFileDCImpl::SetBrush(const wxBrush& brush) @@ -1080,7 +1078,7 @@ void wxSVGFileDCImpl::DoDrawBitmap(const class wxBitmap & bmp, wxCoord x, wxCoor // If we don't have any bitmap handler yet, use the default one. if ( !m_bmp_handler ) - m_bmp_handler = new wxSVGBitmapFileHandler(); + m_bmp_handler.reset(new wxSVGBitmapFileHandler()); m_bmp_handler->ProcessBitmap(bmp, x, y, *m_outfile); }