all repos — fluxbox @ 75f8d95c178b8d1bcb9f96d9f8b113af23a04ad3

custom fork of the fluxbox windowmanager

fixed bug #1718112, memory leak in FbWindow::textProperty
fluxgen fluxgen
commit

75f8d95c178b8d1bcb9f96d9f8b113af23a04ad3

parent

cf9c58bb0bbf80fb0f192e7c145ff851d4ca9050

1 files changed, 26 insertions(+), 9 deletions(-)

jump to
M src/FbTk/FbWindow.ccsrc/FbTk/FbWindow.cc

@@ -461,47 +461,64 @@ m_parent = &parent;

if (continuing) // we will continue managing this window after reparent updateGeometry(); } - +struct TextPropPtr { + TextPropPtr(XTextProperty& prop):m_prop(prop) {} + ~TextPropPtr() { + if (m_prop.value != 0) { + XFree(m_prop.value); + m_prop.value = 0; + } + } + XTextProperty& m_prop; +}; std::string FbWindow::textProperty(Atom property) const { XTextProperty text_prop; + TextPropPtr helper(text_prop); char ** stringlist = 0; int count = 0; std::string ret; static Atom m_utf8string = XInternAtom(display(), "UTF8_STRING", False); - if (XGetTextProperty(display(), window(), &text_prop, property) == 0) + if (XGetTextProperty(display(), window(), &text_prop, property) == 0) { return ""; + } - if (text_prop.value == 0 || text_prop.nitems == 0) + if (text_prop.value == 0 || text_prop.nitems == 0) { return ""; + } if (text_prop.encoding == XA_STRING) { - if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0) + if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0) { return ""; + } ret = FbStringUtil::XStrToFb(stringlist[0]); } else if (text_prop.encoding == m_utf8string && text_prop.format == 8) { #ifdef X_HAVE_UTF8_STRING Xutf8TextPropertyToTextList(display(), &text_prop, &stringlist, &count); - if (count == 0 || stringlist == 0) + if (count == 0 || stringlist == 0) { return ""; + } #else - if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0 || stringlist == 0) + if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0 || stringlist == 0) { return ""; + } #endif ret = stringlist[0]; } else { // still returns a "StringList" despite the different name XmbTextPropertyToTextList(display(), &text_prop, &stringlist, &count); - if (count == 0 || stringlist == 0) + if (count == 0 || stringlist == 0) { return ""; - + } ret = FbStringUtil::LocaleStrToFb(stringlist[0]); } // they all use stringlist - if (stringlist) + if (stringlist) { XFreeStringList(stringlist); + } + return ret; }