summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Grenville <pyxlcy@gmail.com>2012-09-12 12:14:24 +0800
committerRichard Grenville <pyxlcy@gmail.com>2012-09-12 12:14:24 +0800
commit17b8a50161ab84a7b1d05d69b14a81d9a98e4432 (patch)
treedef8e6b45d1e8430911b6cbca8a847d7191c3860
parent05b229f2a0405f5eec0af1ba55a71923ed192d55 (diff)
downloadtdebase-17b8a50161ab84a7b1d05d69b14a81d9a98e4432.tar.gz
tdebase-17b8a50161ab84a7b1d05d69b14a81d9a98e4432.zip
Bug fix: Double free when XQueryTree() fails
Take care of failure of XQueryTree() to prevent it from causing a double-free crash. This usually happens when X is initializing and windows are constantly changing.
-rw-r--r--compton.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/compton.c b/compton.c
index ef157953c..3101771f2 100644
--- a/compton.c
+++ b/compton.c
@@ -1022,7 +1022,7 @@ paint_all(Display *dpy, XserverRegion region) {
}
#ifdef DEBUG_REPAINT
- printf(" 0x%x", w->id);
+ printf(" %#010lx", w->id);
#endif
if (clip_changed) {
@@ -1418,8 +1418,17 @@ map_win(Display *dpy, Window id,
Window *tchildren;
unsigned tnchildren;
- XQueryTree(dpy, wid, &troot, &parent, &tchildren, &tnchildren);
- XFree(tchildren);
+ // XQueryTree probably fails if you run compton when X is somehow
+ // initializing (like add it in .xinitrc). In this case
+ // just leave it alone.
+ if(!XQueryTree(dpy, wid, &troot, &parent, &tchildren,
+ &tnchildren)) {
+ wid = 0;
+ break;
+ }
+
+ if (tchildren)
+ XFree(tchildren);
wid = parent;
}
@@ -2934,11 +2943,20 @@ main(int argc, char **argv) {
&& !array_wid_exists(children, nchildren, wid)) {
Window troot;
Window parent;
- Window *tchildren;
+ Window *tchildren = 0;
unsigned tnchildren;
- XQueryTree(dpy, wid, &troot, &parent, &tchildren, &tnchildren);
- XFree(tchildren);
+ // XQueryTree probably fails if you run compton when X is somehow
+ // initializing (like add it in .xinitrc). In this case
+ // just leave it alone.
+ if(!XQueryTree(dpy, wid, &troot, &parent, &tchildren,
+ &tnchildren)) {
+ wid = 0;
+ break;
+ }
+
+ if (tchildren)
+ XFree(tchildren);
wid = parent;
}