From a33188b2a844832a0a3267f1ebf0883b3205614e Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sat, 19 May 2007 11:47:15 +0000 Subject: fixed bug #1718112, memory leak in FbWindow::textProperty --- ChangeLog | 3 +++ src/FbTk/FbWindow.cc | 35 ++++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22f73c8..c50450a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ (Format: Year/Month/Day) Changes for 1.1: +*07/05/19: + * Fixed bug #1718112, memory leak in FbWindow::textProperty ( Henrik ) + FbTk/FbWindow.cc *07/05/17: * Fixed some window placement issues (thanks Tomas Janousek) ScreenPlacement.cc 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