From 4f96a26e8ad04cd7e2fd9380fff305edd3e07346 Mon Sep 17 00:00:00 2001
From: Alcor <alcor@tilde.club>
Date: Sun, 15 Mar 2026 17:44:23 +0100
Subject: [PATCH 01/19] window: Fix use-after-free in windowClose()

---
 window.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/window.c b/window.c
index 2e79a65..3182a47 100644
--- a/window.c
+++ b/window.c
@@ -478,14 +478,17 @@ void windowClose(uint num) {
 	if (windows[num]->id == Network) return;
 	struct Window *window = windowRemove(num);
 	completeRemove(window->id, NULL);
-	windowFree(window);
 	if (swap >= num) swap--;
 	if (show == num) {
 		windowShow(swap);
+		windowFree(window);
 		swap = show;
-	} else if (show > num) {
-		show--;
-		mainUpdate();
+	} else {
+		windowFree(window);
+		if (show > num) {
+			show--;
+			mainUpdate();
+		}
 	}
 	statusUpdate();
 }
-- 
2.47.3

