diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index 1ed1d37c23..69ee7f2a86 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -83,6 +83,9 @@ CAIRO_GAL_BASE::~CAIRO_GAL_BASE() if( context ) cairo_destroy( context ); + + for( auto imageSurface : imageSurfaces ) + cairo_surface_destroy( imageSurface ); } @@ -508,7 +511,9 @@ void CAIRO_GAL_BASE::DrawBitmap( const BITMAP_BASE& aBitmap ) cairo_surface_mark_dirty( image ); cairo_set_source_surface( currentContext, image, 0, 0 ); cairo_paint( currentContext ); - cairo_surface_destroy( image ); + + // store the image handle so it can be destroyed later + imageSurfaces.push_back( image ); isElementAdded = true; @@ -929,6 +934,11 @@ void CAIRO_GAL_BASE::EnableDepthTest( bool aEnabled ) void CAIRO_GAL_BASE::resetContext() { + for( auto imageSurface : imageSurfaces ) + cairo_surface_destroy( imageSurface ); + + imageSurfaces.clear(); + ClearScreen(); // Compute the world <-> screen transformations diff --git a/include/gal/cairo/cairo_gal.h b/include/gal/cairo/cairo_gal.h index ef8a0fb125..1f46e85c4b 100644 --- a/include/gal/cairo/cairo_gal.h +++ b/include/gal/cairo/cairo_gal.h @@ -304,6 +304,9 @@ protected: cairo_t* context; ///< Cairo image cairo_surface_t* surface; ///< Cairo surface + /// List of surfaces that were created by painting images, to be cleaned up later + std::vector imageSurfaces; + std::vector xformStack; void flushPath();