diff --git a/dlls/user32/edit.c b/dlls/user32/edit.c
index 190e9c6..e4ce96a 100644
--- a/dlls/user32/edit.c
+++ b/dlls/user32/edit.c
@@ -5390,7 +5390,7 @@ static LRESULT EditWndProc_common( HWND hwnd, UINT msg,
 		break;
 	}
 
-	if (es) EDIT_UnlockBuffer(es, FALSE);
+	if (IsWindow(hwnd) && es) EDIT_UnlockBuffer(es, FALSE);
 
         TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd, msg, SPY_GetMsgName(msg, hwnd), result);
 
