wbemprox: Add reference counting to the query object.

This commit is contained in:
Hans Leidekker 2012-06-28 09:25:13 +02:00 committed by Alexandre Julliard
parent 0ceee481fe
commit 992d1e1559
3 changed files with 20 additions and 6 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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 *,