From f05618bd002d6468cc6d5172d475be593d45972e Mon Sep 17 00:00:00 2001
From: Marcus Meissner <marcus@jet.franken.de>
Date: Wed, 2 May 2001 01:08:59 +0000
Subject: [PATCH] Do not HeapFree() memory not allocated by us in
 COMBO_GetText. Convert return value from LB_GETTEXT into COMBO_GetText.

---
 controls/combo.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/controls/combo.c b/controls/combo.c
index 4e18dd85505..453974f69e1 100644
--- a/controls/combo.c
+++ b/controls/combo.c
@@ -1498,6 +1498,9 @@ static LRESULT COMBO_ItemOp( LPHEADCOMBO lphc, UINT msg, LPARAM lParam )
 
 /***********************************************************************
  *           COMBO_GetText
+ *
+ * NOTE! LB_GETTEXT does not count terminating \0, WM_GETTEXT does.
+ *       also LB_GETTEXT might return values < 0, WM_GETTEXT doesn't.
  */
 static LRESULT COMBO_GetText( LPHEADCOMBO lphc, INT N, LPARAM lParam, BOOL unicode)
 {
@@ -1539,8 +1542,8 @@ static LRESULT COMBO_GetText( LPHEADCOMBO lphc, INT N, LPARAM lParam, BOOL unico
 				strncpyW(lpText, lpBuffer, (N > n) ? n+1 : N-1);
 			    lpText[N - 1] = '\0';
 			}
+	                HeapFree( GetProcessHeap(), 0, lpBuffer );
                    }
-	           HeapFree( GetProcessHeap(), 0, lpBuffer );
 	       }
 	   }
 	   else
@@ -1566,10 +1569,14 @@ static LRESULT COMBO_GetText( LPHEADCOMBO lphc, INT N, LPARAM lParam, BOOL unico
 				strncpy(lpText, lpBuffer, (N > n) ? n+1 : N-1);
 			    lpText[N - 1] = '\0';
 			}
+	                HeapFree( GetProcessHeap(), 0, lpBuffer );
                    }
-	           HeapFree( GetProcessHeap(), 0, lpBuffer );
 	       }
 	   }
+	   if (n<0)
+	       n=0;
+	   else
+	       n++;
 	   return (LRESULT)n;
        }
    }
-- 
GitLab