(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
authorDarkvater
Sat, 13 Jan 2007 15:50:36 +0000
changeset 5893 16a86ac09d80
parent 5892 c5ac6df90e4b
child 5894 eb5ff472c10f
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
src/window.cpp
--- a/src/window.cpp	Sat Jan 13 15:24:31 2007 +0000
+++ b/src/window.cpp	Sat Jan 13 15:50:36 2007 +0000
@@ -902,14 +902,19 @@
 void UnInitWindowSystem(void)
 {
 	Window **wz;
-	/* Delete all malloced widgets, and reset z-array */
+
+restart_search:
+	/* Delete all windows, reset z-array.
+	 *When we find the window to delete, we need to restart the search
+	 * as deleting this window could cascade in deleting (many) others
+	 * anywhere in the z-array. We call DeleteWindow() so that it can properly
+	 * release own alloc'd memory, which otherwise could result in memleaks */
 	FOR_ALL_WINDOWS(wz) {
-		free((*wz)->widget);
-		(*wz)->widget = NULL;
-		(*wz)->widget_count = 0;
-		*wz = NULL;
+		DeleteWindow(*wz);
+		goto restart_search;
 	}
-	_last_z_window = _z_windows;
+
+	assert(_last_z_window == _z_windows);
 }
 
 void ResetWindowSystem(void)