ole32: Add a ref-count to the handle structure.

Based on a patch by Dmitry Timoshkov.

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2020-08-11 12:49:50 +01:00 committed by Alexandre Julliard
parent 54b6cbc287
commit fe3421ba2c
1 changed files with 7 additions and 0 deletions

View File

@ -45,6 +45,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(storage);
struct handle_wrapper
{
LONG ref;
HGLOBAL hglobal;
ULONG size;
BOOL delete_on_release;
@ -52,8 +53,13 @@ struct handle_wrapper
static void handle_release(struct handle_wrapper *handle)
{
ULONG ref = InterlockedDecrement(&handle->ref);
if (!ref)
{
if (handle->delete_on_release) GlobalFree(handle->hglobal);
HeapFree(GetProcessHeap(), 0, handle);
}
}
static struct handle_wrapper *handle_create(HGLOBAL hglobal, BOOL delete_on_release)
@ -70,6 +76,7 @@ static struct handle_wrapper *handle_create(HGLOBAL hglobal, BOOL delete_on_rele
HeapFree(GetProcessHeap(), 0, handle);
return NULL;
}
handle->ref = 1;
handle->hglobal = hglobal;
handle->size = GlobalSize(hglobal);
handle->delete_on_release = delete_on_release;