Sfoglia il codice sorgente

fix(x11): free the correct XQueryTree child list in anythingFullscreen (per-frame leak) (#643)

X11FullScreenDetector::anythingFullscreen() runs every frame. It calls
XQueryTree a second time on our own window solely to learn its parent,
which allocates a `schildren` list that must be XFree'd. The cleanup
freed the wrong pointer:

    if (schildren) {
        XFree (children);   // frees the OUTER list, not schildren
    }

Consequences:
- `schildren` is never freed -> one window-list leaks every frame. On a
  multi-window X11 desktop this grows RSS without bound (observed ~8 GB
  per instance after ~40h).
- `children` is freed early while the loop below still reads children[i]
  (use-after-free), then freed again at the end (double-free) whenever
  our window has children.
- The early `return false` on inner-XQueryTree failure also leaked
  `children`.

Fix: XFree(schildren) in the guard, and XFree(children) before the early
return. `children` is still freed once at the end as before.

Verified with heaptrack: the per-frame `render() -> anythingFullscreen()
-> XQueryTree` leak stack disappears; total leaked over a 90s run drops
from 55.2M to 9.5M (remainder is one-time setup allocations).

Co-authored-by: Starkka15 <starkka15@users.noreply.github.com>
Starkka15 1 mese fa
parent
commit
96da7d91e0

+ 5 - 1
src/WallpaperEngine/Render/Drivers/Detectors/X11FullScreenDetector.cpp

@@ -71,11 +71,15 @@ bool X11FullScreenDetector::anythingFullscreen () const {
 	unsigned int num_children;
 
 	if (!XQueryTree (this->m_display, ourWindow, &root, &parentWindow, &schildren, &num_children)) {
+	    XFree (children);
 	    return false;
 	}
 
+	// Free ourWindow's child list — we only queried it to learn parentWindow.
+	// This previously freed `children` (the outer list) by mistake, leaking
+	// schildren every frame and prematurely freeing the list still used below.
 	if (schildren) {
-	    XFree (children);
+	    XFree (schildren);
 	}
     }