fixed 4 memory leaks
authorChristoph von Wittich <christoph_vw@reactos.org>
Fri, 28 Oct 2005 00:14:27 +0000 (00:14 +0000)
committerChristoph von Wittich <christoph_vw@reactos.org>
Fri, 28 Oct 2005 00:14:27 +0000 (00:14 +0000)
svn path=/trunk/; revision=18819

reactos/subsys/system/regedit/childwnd.c
reactos/subsys/system/regedit/listview.c
reactos/subsys/system/regedit/main.c
reactos/subsys/system/regedit/main.h
reactos/subsys/system/regedit/treeview.c

index 824abb9..10c8aaf 100644 (file)
@@ -310,6 +310,9 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
         }
         goto def;
     case WM_DESTROY:
+               DestroyTreeView();
+               DestroyListView(pChildWnd->hListWnd);
+               DestroyMainMenu();
         HeapFree(GetProcessHeap(), 0, pChildWnd);
         pChildWnd = NULL;
         PostQuitMessage(0);
index c88e26d..bc4a4a4 100644 (file)
@@ -494,6 +494,24 @@ fail:
     return NULL;
 }
 
+void DestroyListView(HWND hwndLV) {
+    INT count, i;
+       LVITEM item;
+
+    if (g_valueName)
+        HeapFree(GetProcessHeap(), 0, g_valueName);
+
+    count = ListView_GetItemCount(hwndLV);
+    for (i = 0; i < count; i++) {
+        item.mask = LVIF_PARAM;
+        item.iItem = i;
+        ListView_GetItem(hwndLV, &item);
+        free(((LINE_INFO*)item.lParam)->name);
+        HeapFree(GetProcessHeap(), 0, (void*)item.lParam);
+    }
+}
+
 BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPCTSTR keyPath)
 {
     DWORD max_sub_key_len;
index 4f99a70..a570d30 100644 (file)
@@ -181,10 +181,19 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
 
 /******************************************************************************/
 
+/* we need to destroy the main menu before destroying the main window
+   to avoid a memory leak */
+
+void DestroyMainMenu() {
+       DestroyMenu(hMenuFrame);
+}
+
+/******************************************************************************/
+
 void ExitInstance(HINSTANCE hInstance)
 {
     UnregisterHexEditorClass(hInstance);
-    DestroyMenu(hMenuFrame);
+    
     DestroyMenu(hPopupMenus);
     UnloadAclUiDll();
 }
index cf1b6be..9f3e606 100644 (file)
@@ -107,6 +107,9 @@ extern HTREEITEM InsertNode(HWND hwndTV, HTREEITEM hItem, LPTSTR name);
 extern HWND StartKeyRename(HWND hwndTV);
 extern BOOL CreateNewKey(HWND hwndTV, HTREEITEM hItem);
 extern BOOL SelectNode(HWND hwndTV, LPCTSTR keyPath);
+extern void DestroyTreeView( void );
+extern void DestroyListView( HWND hwndLV );
+extern void DestroyMainMenu( void );
 
 /* edit.c */
 extern BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName, BOOL EditBin);
index 7fa5276..495ec95 100644 (file)
@@ -101,7 +101,9 @@ LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey)
     if (maxLen == -1) return NULL;
     if (!hItem) hItem = TreeView_GetSelection(hwndTV);
     if (!hItem) return NULL;
-    if (!get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen)) return NULL;
+    if (!get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen)) {
+               return NULL;
+       }
     return pathBuffer;
 }
 
@@ -561,6 +563,11 @@ HWND CreateTreeView(HWND hwndParent, LPTSTR pHostName, int id)
     return hwndTV;
 }
 
+void DestroyTreeView() {
+       if (pathBuffer)
+               HeapFree(GetProcessHeap(), 0, pathBuffer);
+}
+
 BOOL SelectNode(HWND hwndTV, LPCTSTR keyPath)
 {
        HTREEITEM hRoot, hItem;