Commit 992d1e15 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

wbemprox: Add reference counting to the query object.

parent 0ceee481
......@@ -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;
......
......@@ -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;
}
......
......@@ -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 *,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment