Dear suckless developers,
The manpage of XGetTextProperty mentions:
> An extra byte containing null (which is not included in the nitems
> member) is stored at the end of the value field of text_prop_return.
Which, if I understand correctly, means that the value field of the
property is dynamically allocated at every successful run of this
function, and even if nitem equals zero, in which case a bare '\0' is
stored into the field. Hence this patch, which frees the value field
at two places where this was not handled.
Sincerely,
Virgile Andreani
diff --git a/lsw.c b/lsw.c
index 9b01f6a..c821f11 100644
--- a/lsw.c
+++ b/lsw.c
@@ -52,9 +52,13 @@ getname(Window win) {
int n;
XTextProperty prop;
- if(!XGetTextProperty(dpy, win, &prop, netwmname) || prop.nitems == 0)
- if(!XGetWMName(dpy, win, &prop) || prop.nitems == 0)
+ prop.value = NULL;
+ if(!XGetTextProperty(dpy, win, &prop, netwmname) || prop.nitems == 0) {
+ if(prop.value != NULL)
+ XFree(prop.value);
+ if(!XGetWMName(dpy, win, &prop))
return "";
+ }
if(!XmbTextPropertyToTextList(dpy, &prop, &list, &n) && n > 0) {
strncpy(buf, list[0], sizeof buf);
XFreeStringList(list);