Skip to content

Commit

Permalink
Fix 3 memory issues in the skin parser (#1665)
Browse files Browse the repository at this point in the history
1. (Major) - leaked the SVG parse tree all the time
2. (Medium) - leaked a reference to a Gradient when drawing
3. (Small) - didn't forget images when reloading by path, although that
   API was unused

Addresses #1647
  • Loading branch information
baconpaul authored Mar 23, 2020
1 parent 16bc49e commit 5edda34
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/common/gui/CScalableBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ CScalableBitmap::~CScalableBitmap()
}
offscreenCache.clear();

if( svgImage )
{
nsvgDelete( svgImage );
}
instances--;
//std::cout << " Destroy CScalableBitmap. instances=" << instances << " id=" << resourceID << " fn=" << fname << std::endl;
}
Expand Down Expand Up @@ -457,6 +461,7 @@ void CScalableBitmap::drawSVG(CDrawContext* dc,
VSTGUI::CPoint p1 = gradXform.inverse().transform(s1);

dc->fillLinearGradient(gp, *cg, p0, p1, evenOdd);
cg->forget();
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions src/common/gui/SkinSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class SkinDB

class SkinConsumingComponnt {
public:
virtual ~SkinConsumingComponnt() {
}
virtual void setSkin( Skin::ptr_t s ) { skin = s; }
protected:
Skin::ptr_t skin;
Expand Down
6 changes: 4 additions & 2 deletions src/common/gui/SurgeBitmaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ CScalableBitmap* SurgeBitmaps::getBitmapByStringID(std::string id)

CScalableBitmap* SurgeBitmaps::loadBitmapByPath(std::string path )
{
if( bitmap_file_registry.find(path) != bitmap_file_registry.end() )
{
bitmap_file_registry[path]->forget();
}
bitmap_file_registry[path] = new CScalableBitmap(path, frame);
return bitmap_file_registry[path];
}
Expand All @@ -114,7 +118,6 @@ CScalableBitmap* SurgeBitmaps::loadBitmapByPathForID(std::string path, int id)
{
if( bitmap_registry.find(id) != bitmap_registry.end() )
{
// FIXME - think about ownership here
bitmap_registry[id]->forget();
}
bitmap_registry[id] = new CScalableBitmap( path, frame );
Expand All @@ -125,7 +128,6 @@ CScalableBitmap* SurgeBitmaps::loadBitmapByPathForStringID(std::string path, std
{
if( bitmap_stringid_registry.find(id) != bitmap_stringid_registry.end() )
{
// FIXME - think about ownership here
bitmap_stringid_registry[id]->forget();
}
bitmap_stringid_registry[id] = new CScalableBitmap( path, frame );
Expand Down

0 comments on commit 5edda34

Please sign in to comment.