From 2db311a843e2830105c174190d1cd6b5a39a7746 Mon Sep 17 00:00:00 2001
From: Andrew Talbot <andrew.talbot@talbotville.com>
Date: Sun, 27 Apr 2008 14:17:30 +0100
Subject: [PATCH] comctl32: Dangling pointers fix.

---
 dlls/comctl32/comboex.c  | 4 +++-
 dlls/comctl32/trackbar.c | 3 ++-
 dlls/comctl32/treeview.c | 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/dlls/comctl32/comboex.c b/dlls/comctl32/comboex.c
index e79831d2b05..cfcfed8965e 100644
--- a/dlls/comctl32/comboex.c
+++ b/dlls/comctl32/comboex.c
@@ -1600,9 +1600,11 @@ static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr)
     if (infoPtr->defaultFont)
 	DeleteObject (infoPtr->defaultFont);
 
+    SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
+
     /* free comboex info data */
     Free (infoPtr);
-    SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
+
     return 0;
 }
 
diff --git a/dlls/comctl32/trackbar.c b/dlls/comctl32/trackbar.c
index e81d55f2ec7..a25f81ebdc9 100644
--- a/dlls/comctl32/trackbar.c
+++ b/dlls/comctl32/trackbar.c
@@ -1452,9 +1452,10 @@ TRACKBAR_Destroy (TRACKBAR_INFO *infoPtr)
     if (infoPtr->hwndToolTip)
     	DestroyWindow (infoPtr->hwndToolTip);
 
-    Free (infoPtr);
     SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
     CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
+    Free (infoPtr);
+
     return 0;
 }
 
diff --git a/dlls/comctl32/treeview.c b/dlls/comctl32/treeview.c
index 2b71a3b25d3..fb67c24960e 100644
--- a/dlls/comctl32/treeview.c
+++ b/dlls/comctl32/treeview.c
@@ -1019,7 +1019,6 @@ static void
 TREEVIEW_FreeItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
 {
     DPA_DeletePtr(infoPtr->items, DPA_GetPtrIndex(infoPtr->items, item));
-    Free(item);
     if (infoPtr->selectedItem == item)
         infoPtr->selectedItem = NULL;
     if (infoPtr->hotItem == item)
@@ -1032,6 +1031,7 @@ TREEVIEW_FreeItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
         infoPtr->dropItem = NULL;
     if (infoPtr->insertMarkItem == item)
         infoPtr->insertMarkItem = NULL;
+    Free(item);
 }