Fix: Memory leak - icon's pixbufs were not destroyed
authorzaxl <zaxl@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 17 Feb 2008 16:58:16 +0000 (16:58 +0000)
committerzaxl <zaxl@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 17 Feb 2008 16:58:16 +0000 (16:58 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@876 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/src/graphics.c
navit/src/graphics.h
navit/src/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c
navit/src/graphics/opengl/graphics_opengl.c

index b262d79..c8bd0ae 100644 (file)
@@ -152,6 +152,13 @@ graphics_image_new(struct graphics *gra, char *path)
        return this_;
 }
 
+void graphics_image_free(struct graphics *gra, struct graphics_image *img)
+{
+       if (gra->meth.image_free)
+               gra->meth.image_free(gra->priv, img->priv);
+       g_free(img);
+}
+
 void
 graphics_draw_restore(struct graphics *this_, struct point *p, int w, int h)
 {
@@ -394,6 +401,8 @@ xdisplay_draw_elements(struct graphics *gra, GHashTable *display_list, struct it
                                                p.x=di->pnt[0].x - img->hot.x;
                                                p.y=di->pnt[0].y - img->hot.y;
                                                gra->meth.draw_image(gra->priv, gra->gc[0]->priv, &p, img->priv);
+                                               graphics_image_free(gra, img);
+                                               img = NULL;
                                        }
                                        break;
                                case element_image:
@@ -584,7 +593,7 @@ graphics_draw(struct graphics *gra, struct displaylist *displaylist, GList *maps
 #endif
        profile(0,NULL);
        do_draw(displaylist, trans, mapsets, order);
-       profile(1,"do_draw");
+//     profile(1,"do_draw");
        graphics_displaylist_draw(gra, displaylist, trans, l);
        profile(1,"xdisplay_draw");
        profile(0,"end");
index ac59589..1c975c9 100644 (file)
@@ -46,6 +46,7 @@ struct graphics_methods {
        void (*register_resize_callback)(struct graphics_priv *gr, void (*callback)(void *data, int w, int h), void *data);
        void (*register_button_callback)(struct graphics_priv *gr, void (*callback)(void *data, int pressed, int button, struct point *p), void *data);
        void (*register_motion_callback)(struct graphics_priv *gr, void (*callback)(void *data, struct point *p), void *data);
+       void (*image_free)(struct graphics_priv *gr, struct graphics_image_priv *priv);
 };
 
 
@@ -111,6 +112,7 @@ void graphics_gc_set_foreground(struct graphics_gc *gc, struct color *c);
 void graphics_gc_set_background(struct graphics_gc *gc, struct color *c);
 void graphics_gc_set_linewidth(struct graphics_gc *gc, int width);
 struct graphics_image *graphics_image_new(struct graphics *gra, char *path);
+void graphics_image_free(struct graphics *gra, struct graphics_image *img);
 void graphics_draw_restore(struct graphics *this_, struct point *p, int w, int h);
 void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode);
 void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count);
index 2d5dd65..18b30ec 100644 (file)
@@ -243,6 +243,14 @@ image_new(struct graphics_priv *gr, struct graphics_image_methods *meth, char *n
        return ret;
 }
 
+static void 
+image_free(struct graphics_priv *gr, struct graphics_image_priv *priv)
+{
+       if (priv->pixbuf)
+               gdk_pixbuf_unref(priv->pixbuf);
+       g_free(priv);
+}
+
 static void
 draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc, struct point *p, int count)
 {
@@ -822,6 +830,7 @@ static struct graphics_methods graphics_methods = {
        register_resize_callback,
        register_button_callback,
        register_motion_callback,
+       image_free,
 };
 
 static struct graphics_priv *
index 7af5f29..9ad7bbe 100644 (file)
@@ -776,6 +776,7 @@ static struct graphics_methods graphics_methods = {
        register_resize_callback,
        register_button_callback,
        register_motion_callback,
+       NULL,   // image_free
 };
 
 static struct graphics_priv *