From 40afb51a70ae491011f44dc9e6c1bbf59cf8bd00 Mon Sep 17 00:00:00 2001 From: Detlef Riekenberg Date: Fri, 3 May 2013 09:22:43 +0200 Subject: [PATCH] user32: The app owns the text buffer memory after an EM_GETHANDLE. --- dlls/user32/edit.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/dlls/user32/edit.c b/dlls/user32/edit.c index 126ab1290b5..8910748d1e0 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);