Detlef Riekenberg : user32: The app owns the text buffer memory after an EM_GETHANDLE.

Alexandre Julliard julliard at winehq.org
Fri May 17 14:24:34 CDT 2013


Module: wine
Branch: master
Commit: 40afb51a70ae491011f44dc9e6c1bbf59cf8bd00
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=40afb51a70ae491011f44dc9e6c1bbf59cf8bd00

Author: Detlef Riekenberg <wine.dev at web.de>
Date:   Fri May  3 09:22:43 2013 +0200

user32: The app owns the text buffer memory after an EM_GETHANDLE.

---

 dlls/user32/edit.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/dlls/user32/edit.c b/dlls/user32/edit.c
index 126ab12..8910748 100644
--- a/dlls/user32/edit.c
+++ b/dlls/user32/edit.c
@@ -151,6 +151,7 @@ typedef struct
 	HLOCAL hloc32W;			/* our unicode local memory block */
 	HLOCAL hloc32A;			/* alias for ANSI control receiving EM_GETHANDLE
 				   	   or EM_SETHANDLE */
+        HLOCAL hlocapp;                 /* The text buffer handle belongs to the app */
 	/*
 	 * IME Data
 	 */
@@ -1264,6 +1265,8 @@ static inline void text_buffer_changed(EDITSTATE *es)
  */
 static void EDIT_LockBuffer(EDITSTATE *es)
 {
+        if (es->hlocapp) return;
+
 	if (!es->text) {
 
 	    if(!es->hloc32W) return;
@@ -1305,6 +1308,7 @@ static void EDIT_LockBuffer(EDITSTATE *es)
  */
 static void EDIT_UnlockBuffer(EDITSTATE *es, BOOL force)
 {
+        if (es->hlocapp) return;
 
 	/* Edit window might be already destroyed */
 	if(!IsWindow(es->hwndSelf))
@@ -2485,6 +2489,11 @@ static HLOCAL EDIT_EM_GetHandle(EDITSTATE *es)
 	    hLocal = es->hloc32A;
 	}
 
+        EDIT_UnlockBuffer(es, TRUE);
+
+        /* The text buffer handle belongs to the app */
+        es->hlocapp = hLocal;
+        /* The app has knowledge of the text buffer handle */
         es->flags |= EF_APP_HAS_HANDLE;
 	TRACE("Returning %p, LocalSize() = %ld\n", hLocal, LocalSize(hLocal));
 	return hLocal;
@@ -2826,6 +2835,9 @@ static void EDIT_EM_SetHandle(EDITSTATE *es, HLOCAL hloc)
 
 	es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
 
+        /* The text buffer handle belongs to the control */
+        es->hlocapp = NULL;
+        /* The app has knowledge of the text buffer handle */
         es->flags |= EF_APP_HAS_HANDLE;
 	EDIT_LockBuffer(es);
 
@@ -4597,10 +4609,11 @@ static LRESULT EDIT_WM_NCDestroy(EDITSTATE *es)
 {
 	LINEDEF *pc, *pp;
 
-	if (es->hloc32W) {
+        /* The app can own the text buffer handle */
+        if (es->hloc32W && (es->hloc32W != es->hlocapp)) {
 		LocalFree(es->hloc32W);
 	}
-	if (es->hloc32A) {
+        if (es->hloc32A && (es->hloc32A != es->hlocapp)) {
 		LocalFree(es->hloc32A);
 	}
 	EDIT_InvalidateUniscribeData(es);




More information about the wine-cvs mailing list