Hans Leidekker : wbemprox: Add reference counting to the query object.
Alexandre Julliard
julliard at winehq.org
Thu Jun 28 13:55:16 CDT 2012
Module: wine
Branch: master
Commit: 992d1e15597389b0d378d86a03ae160050458cb7
URL: http://source.winehq.org/git/wine.git/?a=commit;h=992d1e15597389b0d378d86a03ae160050458cb7
Author: Hans Leidekker <hans at codeweavers.com>
Date: Thu Jun 28 09:25:13 2012 +0200
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 f32ee35..e826202 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 0f41d44..7e5872a 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 6865ddd..e2ffce1 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 *,
More information about the wine-cvs
mailing list