Skip to content

Commit

Permalink
Ensure dangling resources are destroyed in move-assignment operator
Browse files Browse the repository at this point in the history
  • Loading branch information
eakoli committed Nov 20, 2023
1 parent f54953d commit a8bac68
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/include/elements/support/pixmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ namespace cycfi { namespace elements
{
if (this != &rhs)
{
_surface = rhs._surface;
rhs._surface = nullptr;
std::swap(_surface, rhs._surface);
}
return *this;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/src/support/glyphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a8bac68

Please # to comment.