fixed bug #1718112, memory leak in FbWindow::textProperty
This commit is contained in:
parent
cf9c58bb0b
commit
75f8d95c17
1 changed files with 26 additions and 9 deletions
|
@ -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
|
if (continuing) // we will continue managing this window after reparent
|
||||||
updateGeometry();
|
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 {
|
std::string FbWindow::textProperty(Atom property) const {
|
||||||
XTextProperty text_prop;
|
XTextProperty text_prop;
|
||||||
|
TextPropPtr helper(text_prop);
|
||||||
char ** stringlist = 0;
|
char ** stringlist = 0;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
std::string ret;
|
std::string ret;
|
||||||
|
|
||||||
static Atom m_utf8string = XInternAtom(display(), "UTF8_STRING", False);
|
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 "";
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
if (text_prop.value == 0 || text_prop.nitems == 0)
|
if (text_prop.value == 0 || text_prop.nitems == 0) {
|
||||||
return "";
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
if (text_prop.encoding == XA_STRING) {
|
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 "";
|
return "";
|
||||||
|
}
|
||||||
ret = FbStringUtil::XStrToFb(stringlist[0]);
|
ret = FbStringUtil::XStrToFb(stringlist[0]);
|
||||||
} else if (text_prop.encoding == m_utf8string && text_prop.format == 8) {
|
} else if (text_prop.encoding == m_utf8string && text_prop.format == 8) {
|
||||||
#ifdef X_HAVE_UTF8_STRING
|
#ifdef X_HAVE_UTF8_STRING
|
||||||
Xutf8TextPropertyToTextList(display(), &text_prop, &stringlist, &count);
|
Xutf8TextPropertyToTextList(display(), &text_prop, &stringlist, &count);
|
||||||
if (count == 0 || stringlist == 0)
|
if (count == 0 || stringlist == 0) {
|
||||||
return "";
|
return "";
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0 || stringlist == 0)
|
if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0 || stringlist == 0) {
|
||||||
return "";
|
return "";
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
ret = stringlist[0];
|
ret = stringlist[0];
|
||||||
} else {
|
} else {
|
||||||
// still returns a "StringList" despite the different name
|
// still returns a "StringList" despite the different name
|
||||||
XmbTextPropertyToTextList(display(), &text_prop, &stringlist, &count);
|
XmbTextPropertyToTextList(display(), &text_prop, &stringlist, &count);
|
||||||
if (count == 0 || stringlist == 0)
|
if (count == 0 || stringlist == 0) {
|
||||||
return "";
|
return "";
|
||||||
|
}
|
||||||
ret = FbStringUtil::LocaleStrToFb(stringlist[0]);
|
ret = FbStringUtil::LocaleStrToFb(stringlist[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// they all use stringlist
|
// they all use stringlist
|
||||||
if (stringlist)
|
if (stringlist) {
|
||||||
XFreeStringList(stringlist);
|
XFreeStringList(stringlist);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue