From 992d1e15597389b0d378d86a03ae160050458cb7 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Thu, 28 Jun 2012 09:25:13 +0200 Subject: [PATCH] wbemprox: Add reference counting to the query object. --- dlls/wbemprox/class.c | 3 ++- dlls/wbemprox/query.c | 19 +++++++++++++++---- dlls/wbemprox/wbemprox_private.h | 4 +++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/dlls/wbemprox/class.c b/dlls/wbemprox/class.c index f32ee35c052..e82620281bf 100644 --- a/dlls/wbemprox/class.c +++ b/dlls/wbemprox/class.c @@ -60,7 +60,7 @@ static ULONG WINAPI enum_class_object_Release( if (!refs) { TRACE("destroying %p\n", ec); - free_query( ec->query ); + release_query( ec->query ); heap_free( ec ); } return refs; @@ -198,6 +198,7 @@ HRESULT EnumWbemClassObject_create( ec->IEnumWbemClassObject_iface.lpVtbl = &enum_class_object_vtbl; ec->refs = 1; ec->query = query; + addref_query( query ); ec->index = 0; *ppObj = &ec->IEnumWbemClassObject_iface; diff --git a/dlls/wbemprox/query.c b/dlls/wbemprox/query.c index 0f41d44b2d7..7e5872ab8a6 100644 --- a/dlls/wbemprox/query.c +++ b/dlls/wbemprox/query.c @@ -395,16 +395,17 @@ static HRESULT execute_view( struct view *view ) return S_OK; } -static struct query *alloc_query(void) +static struct query *create_query(void) { struct query *query; if (!(query = heap_alloc( sizeof(*query) ))) return NULL; list_init( &query->mem ); + query->refs = 1; return query; } -void free_query( struct query *query ) +static void free_query( struct query *query ) { struct list *mem, *next; @@ -416,13 +417,23 @@ void free_query( struct query *query ) heap_free( query ); } +void addref_query( struct query *query ) +{ + InterlockedIncrement( &query->refs ); +} + +void release_query( struct query *query ) +{ + if (!InterlockedDecrement( &query->refs )) free_query( query ); +} + HRESULT exec_query( const WCHAR *str, IEnumWbemClassObject **result ) { HRESULT hr; struct query *query; *result = NULL; - if (!(query = alloc_query())) return E_OUTOFMEMORY; + if (!(query = create_query())) return E_OUTOFMEMORY; hr = parse_query( str, &query->view, &query->mem ); if (hr != S_OK) goto done; hr = execute_view( query->view ); @@ -430,7 +441,7 @@ HRESULT exec_query( const WCHAR *str, IEnumWbemClassObject **result ) hr = EnumWbemClassObject_create( NULL, query, (void **)result ); done: - if (hr != S_OK) free_query( query ); + release_query( query ); return hr; } diff --git a/dlls/wbemprox/wbemprox_private.h b/dlls/wbemprox/wbemprox_private.h index 6865dddb33a..e2ffce15151 100644 --- a/dlls/wbemprox/wbemprox_private.h +++ b/dlls/wbemprox/wbemprox_private.h @@ -106,11 +106,13 @@ struct view struct query { + LONG refs; struct view *view; struct list mem; }; -void free_query( struct query * ) DECLSPEC_HIDDEN; +void addref_query( struct query * ) DECLSPEC_HIDDEN; +void release_query( struct query *query ) DECLSPEC_HIDDEN; HRESULT exec_query( const WCHAR *, IEnumWbemClassObject ** ) DECLSPEC_HIDDEN; HRESULT parse_query( const WCHAR *, struct view **, struct list * ) DECLSPEC_HIDDEN; HRESULT create_view( const struct property *, const WCHAR *, const struct expr *,