>From 1fa531104d93e98013ec0f48c31a4162103b6dae Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Mon, 18 Apr 2011 20:39:06 +0200
Subject: [PATCH] Plug some (possible) memleaks
PropGetWMClass()
- XAllocClassHint()s a struct for class hint data
- This is filled by XGetClassHint(), which in turn uses Xlib to allocate
some more space for XClassHint members
- Upon XGetClassHint() failure, "default" is libc malloc'd (via strdup),
and is returned to the caller
- Upon XGetClassHint() success, XClassHint members are returned raw --
these members must be freed with XFree() (see XAllocClassHint(3))
- Thus it's up to PropGetWMClass() callers to decide (based upon the return
value) which method (libc free() or XFree()) to use to free res_name
and res_class. This was done nowhere, thus leaking some memory
on every failed PropGetWMClass() call.
- So just strdup the successful res_name/res_class members, XFree() them
while still in PropGetWMClass(), and allow callers to unconditionally
libc free() whatever PropGetWMClass() returns.
---
src/dock.c | 4 ++--
src/properties.c | 7 +++++--
src/session.c | 4 ++--
src/window.c | 8 ++++----
4 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/src/dock.c b/src/dock.c
index 5e7cc93..9d74b49 100644
--- a/src/dock.c
+++ b/src/dock.c
@@ -3015,9 +3015,9 @@ void wDockTrackWindowLaunch(WDock * dock, Window window)
wfree(command);
if (wm_class)
- XFree(wm_class);
+ free(wm_class);
if (wm_instance)
- XFree(wm_instance);
+ free(wm_instance);
}
void wClipUpdateForWorkspaceChange(WScreen * scr, int workspace)
diff --git a/src/properties.c b/src/properties.c
index 7279de1..46bc3ca 100644
--- a/src/properties.c
+++ b/src/properties.c
@@ -71,10 +71,13 @@ int PropGetWMClass(Window window, char **wm_class, char
**wm_instance)
XFree(class_hint);
return False;
}
- *wm_instance = class_hint->res_name;
- *wm_class = class_hint->res_class;
+ *wm_instance = strdup(class_hint->res_name);
+ *wm_class = strdup(class_hint->res_class);
+ XFree(class_hint->res_name);
+ XFree(class_hint->res_class);
XFree(class_hint);
+
return True;
}
diff --git a/src/session.c b/src/session.c
index 4a50f78..811aee3 100644
--- a/src/session.c
+++ b/src/session.c
@@ -257,9 +257,9 @@ static WMPropList *makeWindowState(WWindow * wwin,
WApplication * wapp)
}
if (instance)
- XFree(instance);
+ free(instance);
if (class)
- XFree(class);
+ free(class);
if (command)
wfree(command);
diff --git a/src/window.c b/src/window.c
index bfc0ade..7402b7d 100644
--- a/src/window.c
+++ b/src/window.c
@@ -830,9 +830,9 @@ WWindow *wManageWindow(WScreen *scr, Window window)
wwin->main_window = fPtr->leader;
}
if (instance)
- XFree(instance);
+ free(instance);
if (class)
- XFree(class);
+ free(class);
#undef ADEQUATE
}
@@ -2654,9 +2654,9 @@ WMagicNumber wWindowGetSavedState(Window win)
if (command)
wfree(command);
if (instance)
- XFree(instance);
+ free(instance);
if (class)
- XFree(class);
+ free(class);
return wstate;
}
--
1.7.0.4
--
[-]
mkdir /nonexistentFrom 1fa531104d93e98013ec0f48c31a4162103b6dae Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Mon, 18 Apr 2011 20:39:06 +0200
Subject: [PATCH] Plug some (possible) memleaks
PropGetWMClass()
- XAllocClassHint()s a struct for class hint data
- This is filled by XGetClassHint(), which in turn uses Xlib to allocate
some more space for XClassHint members
- Upon XGetClassHint() failure, "default" is libc malloc'd (via strdup),
and is returned to the caller
- Upon XGetClassHint() success, XClassHint members are returned raw --
these members must be freed with XFree() (see XAllocClassHint(3))
- Thus it's up to PropGetWMClass() callers to decide (based upon the return
value) which method (libc free() or XFree()) to use to free res_name
and res_class. This was done nowhere, thus leaking some memory
on every failed PropGetWMClass() call.
- So just strdup the successful res_name/res_class members, XFree() them
while still in PropGetWMClass(), and allow callers to unconditionally
libc free() whatever PropGetWMClass() returns.
---
src/dock.c | 4 ++--
src/properties.c | 7 +++++--
src/session.c | 4 ++--
src/window.c | 8 ++++----
4 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/src/dock.c b/src/dock.c
index 5e7cc93..9d74b49 100644
--- a/src/dock.c
+++ b/src/dock.c
@@ -3015,9 +3015,9 @@ void wDockTrackWindowLaunch(WDock * dock, Window window)
wfree(command);
if (wm_class)
- XFree(wm_class);
+ free(wm_class);
if (wm_instance)
- XFree(wm_instance);
+ free(wm_instance);
}
void wClipUpdateForWorkspaceChange(WScreen * scr, int workspace)
diff --git a/src/properties.c b/src/properties.c
index 7279de1..46bc3ca 100644
--- a/src/properties.c
+++ b/src/properties.c
@@ -71,10 +71,13 @@ int PropGetWMClass(Window window, char **wm_class, char **wm_instance)
XFree(class_hint);
return False;
}
- *wm_instance = class_hint->res_name;
- *wm_class = class_hint->res_class;
+ *wm_instance = strdup(class_hint->res_name);
+ *wm_class = strdup(class_hint->res_class);
+ XFree(class_hint->res_name);
+ XFree(class_hint->res_class);
XFree(class_hint);
+
return True;
}
diff --git a/src/session.c b/src/session.c
index 4a50f78..811aee3 100644
--- a/src/session.c
+++ b/src/session.c
@@ -257,9 +257,9 @@ static WMPropList *makeWindowState(WWindow * wwin, WApplication * wapp)
}
if (instance)
- XFree(instance);
+ free(instance);
if (class)
- XFree(class);
+ free(class);
if (command)
wfree(command);
diff --git a/src/window.c b/src/window.c
index bfc0ade..7402b7d 100644
--- a/src/window.c
+++ b/src/window.c
@@ -830,9 +830,9 @@ WWindow *wManageWindow(WScreen *scr, Window window)
wwin->main_window = fPtr->leader;
}
if (instance)
- XFree(instance);
+ free(instance);
if (class)
- XFree(class);
+ free(class);
#undef ADEQUATE
}
@@ -2654,9 +2654,9 @@ WMagicNumber wWindowGetSavedState(Window win)
if (command)
wfree(command);
if (instance)
- XFree(instance);
+ free(instance);
if (class)
- XFree(class);
+ free(class);
return wstate;
}
--
1.7.0.4