Added reset of pointer after memory free to avoid double-free crash
authorChristophe CURIS <christophe.curis@free.fr>
Wed, 14 Nov 2012 20:23:32 +0000 (14 21:23 +0100)
committerCarlos R. Mafra <crmafra@gmail.com>
Wed, 14 Nov 2012 22:39:37 +0000 (14 22:39 +0000)
As reported by Rodolfo, there are some cases when working with icons
where a crash can occur, which is related to trying to re-release
some memory that have been already freed previously.

This patch adds a reset-to-NULL of the corresponding pointers so that
on next usage wmaker will know there's no more memory associated with
these pointers.

src/icon.c

index ba059ad..04767d8 100644 (file)
@@ -584,11 +584,15 @@ void wIconSelect(WIcon * icon)
 
 static void unset_icon_image(WIcon *icon)
 {
-       if (icon->file)
+       if (icon->file) {
                wfree(icon->file);
+               icon->file = NULL;
+       }
 
-       if (icon->file_image)
+       if (icon->file_image) {
                RReleaseImage(icon->file_image);
+               icon->file_image = NULL;
+       }
 }
 
 void wIconUpdate(WIcon *icon)
@@ -755,8 +759,7 @@ static int get_rimage_icon_from_wm_hints(WIcon *icon)
        if (!image)
                return 1;
 
-       /* FIXME: If unset_icon_image, pointer double free then crash 
-       unset_icon_image(icon); */
+       unset_icon_image(icon);
        icon->file_image = image;
 
        return 0;