From 75f8d95c178b8d1bcb9f96d9f8b113af23a04ad3 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sat, 19 May 2007 11:42:44 +0000 Subject: fixed bug #1718112, memory leak in FbWindow::textProperty --- src/FbTk/FbWindow.cc | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/FbTk/FbWindow.cc b/src/FbTk/FbWindow.cc index 450ca32..3dce5b8 100644 --- a/src/FbTk/FbWindow.cc +++ b/src/FbTk/FbWindow.cc @@ -461,47 +461,64 @@ void FbWindow::reparent(const FbWindow &parent, int x, int y, bool continuing) { 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; } -- cgit v0.11.2