swm

sigma window manager
git clone git://wolog.xyz/swm
Log | Files | Refs | README | LICENSE

commit 285d27458fe2066e83bec4120fa808b57e2b8d8e
parent 8cca0e74df39393fc073f08a57b029438c367a50
Author: Raymond Cole <rc@wolog.xyz>
Date:   Tue,  5 Nov 2024 18:02:35 +0000

Fix memory leaks

In some edge cases, resources returned by XGetTextProperty() and
XmbTextPropertyToTextList() might not get freed.

Diffstat:
Mclient.c | 22++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/client.c b/client.c @@ -13,7 +13,7 @@ #include "swm.h" -static char *gettitle(Client *c, Atom atom); +static int gettitle(Client *c, Atom atom); static Atom getatomprop(Client *c, Atom prop); static int xerrordummy(Display *dpy, XErrorEvent *ee); @@ -150,28 +150,26 @@ configure(Client *c, int resize) notifyconfigure(c); } -char * +int gettitle(Client *c, Atom prop) { size_t max = c->bytes + sizeof(c->bytes) - c->title; - char **list = NULL; XTextProperty text; + char **list; int n; - if (!XGetTextProperty(dpy, c->win, &text, prop) || !text.nitems) - return NULL; + if (!XGetTextProperty(dpy, c->win, &text, prop)) + return 0; + *c->title = '\0'; if (text.encoding == XA_STRING) { *stpncpy(c->title, (char *)text.value, max - 1) = '\0'; - } else if (XmbTextPropertyToTextList(dpy, &text, &list, &n) >= Success - && n > 0 && *list) { - *stpncpy(c->title, *list, max - 1) = '\0'; + } else if (XmbTextPropertyToTextList(dpy, &text, &list, &n) >= 0) { + if (n > 0) + *stpncpy(c->title, *list, max - 1) = '\0'; XFreeStringList(list); - } else { - XFree(text.value); - return NULL; } XFree(text.value); - return c->title; + return *c->title; } void