Commit cdaec755 authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mihai Moldovan

Make sure XQueryTree results are freed

Fixes ArcticaProject/nx-libs#585
parent 0938cf83
...@@ -426,13 +426,12 @@ void nxagentRemoteWindowsTree(Window window, int level) ...@@ -426,13 +426,12 @@ void nxagentRemoteWindowsTree(Window window, int level)
int i, j; int i, j;
unsigned long rootWin, parentWin; unsigned long rootWin, parentWin;
unsigned int numChildren; unsigned int numChildren;
unsigned long *childList; unsigned long *childList = NULL;
if (!XQueryTree(nxagentDisplay, window, &rootWin, &parentWin, &childList, if (!XQueryTree(nxagentDisplay, window, &rootWin, &parentWin, &childList,
&numChildren)) &numChildren))
{ {
fprintf(stderr, "nxagentRemoteWindowsTree - XQueryTree failed.\n"); fprintf(stderr, "nxagentRemoteWindowsTree - XQueryTree failed.\n");
return; return;
} }
...@@ -3185,7 +3184,7 @@ int nxagentCheckWindowConfiguration(XConfigureEvent* X) ...@@ -3185,7 +3184,7 @@ int nxagentCheckWindowConfiguration(XConfigureEvent* X)
#endif #endif
} }
if (result && nchildren_return) if (children_return)
{ {
XFree(children_return); XFree(children_return);
} }
...@@ -3540,6 +3539,12 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3540,6 +3539,12 @@ int nxagentHandleReparentNotify(XEvent* X)
result = XQueryTree(nxagentDisplay, w, &root_return, result = XQueryTree(nxagentDisplay, w, &root_return,
&parent_return, &children_return, &nchildren_return); &parent_return, &children_return, &nchildren_return);
if (children_return)
{
XFree(children_return);
children_return = NULL;
}
if (!result) if (!result)
{ {
#ifdef WARNING #ifdef WARNING
...@@ -3548,11 +3553,6 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3548,11 +3553,6 @@ int nxagentHandleReparentNotify(XEvent* X)
break; break;
} }
if (result && children_return)
{
XFree(children_return);
}
} }
if (w && !nxagentWindowPtr(w)) if (w && !nxagentWindowPtr(w))
...@@ -3581,9 +3581,10 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3581,9 +3581,10 @@ int nxagentHandleReparentNotify(XEvent* X)
#endif #endif
} }
if (result && nchildren_return) if (children_return)
{ {
XFree(children_return); XFree(children_return);
children_return = NULL;
} }
} }
else else
...@@ -3647,17 +3648,18 @@ int nxagentHandleReparentNotify(XEvent* X) ...@@ -3647,17 +3648,18 @@ int nxagentHandleReparentNotify(XEvent* X)
{ {
result = XQueryTree(nxagentDisplay, w, &rootReturn, &parentReturn, result = XQueryTree(nxagentDisplay, w, &rootReturn, &parentReturn,
&childrenReturn, &nchildrenReturn); &childrenReturn, &nchildrenReturn);
if (parentReturn == rootReturn || parentReturn == 0 || result == 0) if (childrenReturn)
{ {
break; XFree(childrenReturn);
childrenReturn = NULL;
} }
if (result == 1 && childrenReturn != NULL) if (parentReturn == rootReturn || parentReturn == 0 || result == 0)
{ {
XFree(childrenReturn); break;
} }
w = parentReturn; w = parentReturn;
} }
while (True); while (True);
......
...@@ -249,7 +249,7 @@ Bool nxagentRootlessTreesMatch() ...@@ -249,7 +249,7 @@ Bool nxagentRootlessTreesMatch()
{ {
Window root_return; Window root_return;
Window parent_return; Window parent_return;
Window *children_return; Window *children_return = NULL;
unsigned int nChildrenReturn; unsigned int nChildrenReturn;
WindowPtr pTestWin = screenInfo.screens[0]->root -> firstChild; WindowPtr pTestWin = screenInfo.screens[0]->root -> firstChild;
Bool treesMatch = True; Bool treesMatch = True;
......
...@@ -1454,7 +1454,7 @@ void nxagentConfigureWindow(WindowPtr pWin, unsigned int mask) ...@@ -1454,7 +1454,7 @@ void nxagentConfigureWindow(WindowPtr pWin, unsigned int mask)
{ {
Window root_return; Window root_return;
Window parent_return; Window parent_return;
Window *children_return; Window *children_return = NULL;
unsigned int nchildren_return; unsigned int nchildren_return;
Status result; Status result;
...@@ -1473,16 +1473,16 @@ void nxagentConfigureWindow(WindowPtr pWin, unsigned int mask) ...@@ -1473,16 +1473,16 @@ void nxagentConfigureWindow(WindowPtr pWin, unsigned int mask)
} }
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
if (children_return)
{
XFree(children_return);
}
} }
else else
{ {
fprintf(stderr, "nxagentConfigureWindow: Failed QueryTree request.\n "); fprintf(stderr, "nxagentConfigureWindow: Failed QueryTree request.\n ");
} }
if (children_return)
{
XFree(children_return);
}
} }
#endif #endif
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment