From a8bac6838448fe85c76f9a35e6b225f195fbcd48 Mon Sep 17 00:00:00 2001 From: Chris Rudd Date: Mon, 20 Nov 2023 15:39:36 -0600 Subject: [PATCH] Ensure dangling resources are destroyed in move-assignment operator --- lib/include/elements/support/pixmap.hpp | 3 +-- lib/src/support/glyphs.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/include/elements/support/pixmap.hpp b/lib/include/elements/support/pixmap.hpp index b5510892a..9fc7c08ae 100644 --- a/lib/include/elements/support/pixmap.hpp +++ b/lib/include/elements/support/pixmap.hpp @@ -96,8 +96,7 @@ namespace cycfi { namespace elements { if (this != &rhs) { - _surface = rhs._surface; - rhs._surface = nullptr; + std::swap(_surface, rhs._surface); } return *this; } diff --git a/lib/src/support/glyphs.cpp b/lib/src/support/glyphs.cpp index 754108665..18a3b2225 100644 --- a/lib/src/support/glyphs.cpp +++ b/lib/src/support/glyphs.cpp @@ -181,6 +181,13 @@ namespace cycfi { namespace elements { if (&rhs != this) { + if (_glyphs) + cairo_glyph_free(_glyphs); + if (_clusters) + cairo_text_cluster_free(_clusters); + if (_scaled_font) + cairo_scaled_font_destroy(_scaled_font); + _first = rhs._first; _last = rhs._last; _scaled_font = rhs._scaled_font;