Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12166) leak in crop_sprite
Home

[Freeciv-Dev] (PR#12166) leak in crop_sprite

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12166) leak in crop_sprite
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 7 Feb 2005 18:40:09 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12166 >

When calling crop_sprite with a mask, there is a memory leak. 
Apparently gdk_pixbuf_add_alpha() actually allocates an all-new pixbuf 
(which isn't clear unless you read the documentation pretty closely).

-jason

? fog
? fog.c
? fog.png
? foo
? data/isotrident/grid.png
? data/isotrident/grid.xcf
Index: client/gui-gtk-2.0/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/graphics.c,v
retrieving revision 1.34
diff -u -r1.34 graphics.c
--- client/gui-gtk-2.0/graphics.c       5 Feb 2005 01:32:10 -0000       1.34
+++ client/gui-gtk-2.0/graphics.c       8 Feb 2005 02:38:57 -0000
@@ -137,7 +137,9 @@
    * alpha of the mask.  Thus if the mask has 50% alpha the final image will
    * be reduced by 50% alpha.  Note that the mask offset is in coordinates
    * relative to the clipped image not the final image. */
-  if (mask) {
+  if (mask
+      && (mask_pixbuf = sprite_get_pixbuf(mask))
+      && gdk_pixbuf_get_has_alpha(mask_pixbuf)) {
     int x1, y1;
 
     /* The mask offset is the offset of the mask relative to the origin
@@ -151,10 +153,12 @@
     width = CLIP(0, width, mask->width + mask_offset_x);
     height = CLIP(0, height, mask->height + mask_offset_y);
 
-    mask_pixbuf = sprite_get_pixbuf(mask);
+    if (!gdk_pixbuf_get_has_alpha(mypixbuf)) {
+      GdkPixbuf *p2 = mypixbuf;
 
-    gdk_pixbuf_add_alpha(mypixbuf, FALSE, 0, 0, 0);
-    gdk_pixbuf_add_alpha(mask_pixbuf, FALSE, 0, 0, 0);
+      mypixbuf = gdk_pixbuf_add_alpha(mypixbuf, FALSE, 0, 0, 0);
+      g_object_unref(p2);
+    }
 
     for (x1 = 0; x1 < width; x1++) {
       for (y1 = 0; y1 < height; y1++) {

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12166) leak in crop_sprite, Jason Short <=