fixed 4 memory leaks

svn path=/trunk/; revision=18819
This commit is contained in:
Christoph von Wittich 2005-10-28 00:14:27 +00:00
parent 14db8e6026
commit d0cb6cb732
5 changed files with 42 additions and 2 deletions

View 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);

View 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;

View 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();
}

View 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);

View 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;