From 0bdc1cabc08f612b4a29f03e50051a15f2acf71c Mon Sep 17 00:00:00 2001
From: Christophe CURIS <[email protected]>
Date: Wed, 14 Nov 2012 21:23:32 +0100
Subject: [PATCH] Added reset of pointer after memory free to avoid
double-free crash
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 | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/icon.c b/src/icon.c
index ba059ad..04767d8 100644
--- a/src/icon.c
+++ b/src/icon.c
@@ -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;
--
1.7.10.4