Code

Fixed dangling pointers and possible memory leaks with feImage
authorkiirala <kiirala@users.sourceforge.net>
Sat, 16 May 2009 20:38:23 +0000 (20:38 +0000)
committerkiirala <kiirala@users.sourceforge.net>
Sat, 16 May 2009 20:38:23 +0000 (20:38 +0000)
src/display/nr-filter-image.cpp
src/filters/image.cpp

index b50a66086e87fac3ae1ad17aec336a3404cbc159..625aadf803e28ac83726cfa5daf71f3a1f71a79a 100644 (file)
 namespace Inkscape {
 namespace Filters {
 
-FilterImage::FilterImage()
-{
-    feImageHref=NULL;
-    image_pixbuf=NULL;
-    document=NULL;
-}
+FilterImage::FilterImage() :
+    SVGElem(0),
+    document(0),
+    feImageHref(0),
+    image_pixbuf(0)
+}
 
 FilterPrimitive * FilterImage::create() {
     return new FilterImage();
@@ -37,6 +37,7 @@ FilterPrimitive * FilterImage::create() {
 FilterImage::~FilterImage()
 {
         if (feImageHref) g_free(feImageHref);
+        if (image_pixbuf) g_free(image_pixbuf);
 }
 
 int FilterImage::render(FilterSlot &slot, FilterUnits const &units) {
@@ -55,7 +56,7 @@ int FilterImage::render(FilterSlot &slot, FilterUnits const &units) {
         NRArenaItem* ai = sp_item_invoke_show(SVGElem, arena, key, SP_ITEM_SHOW_DISPLAY);
         if (!ai) {
             g_warning("feImage renderer: error creating NRArenaItem for SVG Element");
-            g_free(arena);
+            nr_object_unref((NRObject *) arena);
             return 0;
         }
         pb = new NRPixBlock;
@@ -99,7 +100,7 @@ int FilterImage::render(FilterSlot &slot, FilterUnits const &units) {
         {
             g_warning("FilterImage::render: not enough memory to create pixel buffer. Need %ld.", 4L * width * height);
         }
-        nr_arena_item_unref(ai);
+        sp_item_invoke_hide(SVGElem, key);
         nr_object_unref((NRObject *) arena);
     }
 
@@ -202,7 +203,10 @@ int FilterImage::render(FilterSlot &slot, FilterUnits const &units) {
             }
         }
     }
-    if (free_pb_on_exit) nr_pixblock_release(pb);
+    if (free_pb_on_exit) {
+        nr_pixblock_release(pb);
+        delete pb;
+    }
 
     out->empty = FALSE;
     slot.set(_output, out);
index eda815d8d881f3d785e6ec72b05757dd54180e13..a23ffeee4eba9dbe5ffea29d0fbd313e16dc8907 100644 (file)
@@ -150,6 +150,7 @@ sp_feImage_set(SPObject *object, unsigned int key, gchar const *value)
             if (!feImage->href) return;
             try{
                 Inkscape::URI SVGElem_uri(feImage->href);
+                delete feImage->SVGElemRef;
                 feImage->SVGElemRef = new Inkscape::URIReference(feImage->document);
                 feImage->from_element = true;
                 feImage->SVGElemRef->attach(SVGElem_uri);