summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2007-01-13 15:50:36 +0000
committerDarkvater <darkvater@openttd.org>2007-01-13 15:50:36 +0000
commite832a1d046ea4ea948aab122d5aa8ea9097a9b6a (patch)
tree990cf89b0a0cdb0bffff39bb88714144d71659cb
parent64c30ae737b8019002bb11737ce3f6d20bf4c0fb (diff)
downloadopenttd-e832a1d046ea4ea948aab122d5aa8ea9097a9b6a.tar.xz
(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.
-rw-r--r--src/window.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/window.cpp b/src/window.cpp
index 7977bed0c..045a80c65 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -902,14 +902,19 @@ void InitWindowSystem(void)
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)