Commit 2eb666d6 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

wbemprox: Keep a reference to the table from uncommitted instances.

parent 1d8763bb
...@@ -202,8 +202,7 @@ HRESULT EnumWbemClassObject_create( ...@@ -202,8 +202,7 @@ HRESULT EnumWbemClassObject_create(
ec->IEnumWbemClassObject_iface.lpVtbl = &enum_class_object_vtbl; ec->IEnumWbemClassObject_iface.lpVtbl = &enum_class_object_vtbl;
ec->refs = 1; ec->refs = 1;
ec->query = query; ec->query = addref_query( query );
addref_query( query );
ec->index = 0; ec->index = 0;
*ppObj = &ec->IEnumWbemClassObject_iface; *ppObj = &ec->IEnumWbemClassObject_iface;
...@@ -212,24 +211,25 @@ HRESULT EnumWbemClassObject_create( ...@@ -212,24 +211,25 @@ HRESULT EnumWbemClassObject_create(
return S_OK; return S_OK;
} }
static struct record *create_record( const struct column *columns, UINT num_cols ) static struct record *create_record( struct table *table )
{ {
UINT i; UINT i;
struct record *record; struct record *record;
if (!(record = heap_alloc( sizeof(struct record) ))) return NULL; if (!(record = heap_alloc( sizeof(struct record) ))) return NULL;
if (!(record->fields = heap_alloc( num_cols * sizeof(struct field) ))) if (!(record->fields = heap_alloc( table->num_cols * sizeof(struct field) )))
{ {
heap_free( record ); heap_free( record );
return NULL; return NULL;
} }
for (i = 0; i < num_cols; i++) for (i = 0; i < table->num_cols; i++)
{ {
record->fields[i].type = columns[i].type; record->fields[i].type = table->columns[i].type;
record->fields[i].vartype = columns[i].vartype; record->fields[i].vartype = table->columns[i].vartype;
record->fields[i].u.ival = 0; record->fields[i].u.ival = 0;
} }
record->count = num_cols; record->count = table->num_cols;
record->table = addref_table( table );
return record; return record;
} }
...@@ -252,6 +252,7 @@ static void destroy_record( struct record *record ) ...@@ -252,6 +252,7 @@ static void destroy_record( struct record *record )
UINT i; UINT i;
if (!record) return; if (!record) return;
release_table( record->table );
for (i = 0; i < record->count; i++) for (i = 0; i < record->count; i++)
{ {
if (record->fields[i].type == CIM_STRING || record->fields[i].type == CIM_DATETIME) if (record->fields[i].type == CIM_STRING || record->fields[i].type == CIM_DATETIME)
...@@ -390,14 +391,10 @@ static HRESULT WINAPI class_object_Get( ...@@ -390,14 +391,10 @@ static HRESULT WINAPI class_object_Get(
if (co->record) if (co->record)
{ {
struct table *table = grab_table( co->name );
UINT index; UINT index;
HRESULT hr; HRESULT hr;
if (!table) return WBEM_E_FAILED; if ((hr = get_column_index( co->record->table, wszName, &index )) != S_OK) return hr;
hr = get_column_index( table, wszName, &index );
release_table( table );
if (hr != S_OK) return hr;
return record_get_value( co->record, index, pVal, pType ); return record_get_value( co->record, index, pVal, pType );
} }
return get_propval( ec->query->view, co->index, wszName, pVal, pType, plFlavor ); return get_propval( ec->query->view, co->index, wszName, pVal, pType, plFlavor );
...@@ -450,14 +447,10 @@ static HRESULT WINAPI class_object_Put( ...@@ -450,14 +447,10 @@ static HRESULT WINAPI class_object_Put(
if (co->record) if (co->record)
{ {
struct table *table = grab_table( co->name );
UINT index; UINT index;
HRESULT hr; HRESULT hr;
if (!table) return WBEM_E_FAILED; if ((hr = get_column_index( co->record->table, wszName, &index )) != S_OK) return hr;
hr = get_column_index( table, wszName, &index );
release_table( table );
if (hr != S_OK) return hr;
return record_set_value( co->record, index, pVal ); return record_set_value( co->record, index, pVal );
} }
return put_propval( ec->query->view, co->index, wszName, pVal, Type ); return put_propval( ec->query->view, co->index, wszName, pVal, Type );
...@@ -650,8 +643,7 @@ static HRESULT WINAPI class_object_SpawnInstance( ...@@ -650,8 +643,7 @@ static HRESULT WINAPI class_object_SpawnInstance(
TRACE("%p, %08x, %p\n", iface, lFlags, ppNewInstance); TRACE("%p, %08x, %p\n", iface, lFlags, ppNewInstance);
if (!(record = create_record( view->table->columns, view->table->num_cols ))) if (!(record = create_record( view->table ))) return E_OUTOFMEMORY;
return E_OUTOFMEMORY;
return create_class_object( co->name, NULL, 0, record, ppNewInstance ); return create_class_object( co->name, NULL, 0, record, ppNewInstance );
} }
......
...@@ -290,9 +290,10 @@ static void free_query( struct query *query ) ...@@ -290,9 +290,10 @@ static void free_query( struct query *query )
heap_free( query ); heap_free( query );
} }
void addref_query( struct query *query ) struct query *addref_query( struct query *query )
{ {
InterlockedIncrement( &query->refs ); InterlockedIncrement( &query->refs );
return query;
} }
void release_query( struct query *query ) void release_query( struct query *query )
......
...@@ -321,6 +321,12 @@ void release_table( struct table *table ) ...@@ -321,6 +321,12 @@ void release_table( struct table *table )
if (!InterlockedDecrement( &table->refs )) free_table( table ); if (!InterlockedDecrement( &table->refs )) free_table( table );
} }
struct table *addref_table( struct table *table )
{
InterlockedIncrement( &table->refs );
return table;
}
struct table *grab_table( const WCHAR *name ) struct table *grab_table( const WCHAR *name )
{ {
struct table *table; struct table *table;
...@@ -330,9 +336,8 @@ struct table *grab_table( const WCHAR *name ) ...@@ -330,9 +336,8 @@ struct table *grab_table( const WCHAR *name )
if (!strcmpiW( table->name, name )) if (!strcmpiW( table->name, name ))
{ {
if (table->fill && !table->data) table->fill( table ); if (table->fill && !table->data) table->fill( table );
InterlockedIncrement( &table->refs );
TRACE("returning %p\n", table); TRACE("returning %p\n", table);
return table; return addref_table( table );
} }
} }
return NULL; return NULL;
......
...@@ -91,6 +91,7 @@ struct record ...@@ -91,6 +91,7 @@ struct record
{ {
UINT count; UINT count;
struct field *fields; struct field *fields;
struct table *table;
}; };
enum operator enum operator
...@@ -154,7 +155,7 @@ struct query ...@@ -154,7 +155,7 @@ struct query
struct list mem; struct list mem;
}; };
void addref_query( struct query * ) DECLSPEC_HIDDEN; struct query *addref_query( struct query * ) DECLSPEC_HIDDEN;
void release_query( struct query *query ) DECLSPEC_HIDDEN; void release_query( struct query *query ) DECLSPEC_HIDDEN;
HRESULT exec_query( const WCHAR *, IEnumWbemClassObject ** ) DECLSPEC_HIDDEN; HRESULT exec_query( const WCHAR *, IEnumWbemClassObject ** ) DECLSPEC_HIDDEN;
HRESULT parse_query( const WCHAR *, struct view **, struct list * ) DECLSPEC_HIDDEN; HRESULT parse_query( const WCHAR *, struct view **, struct list * ) DECLSPEC_HIDDEN;
...@@ -163,6 +164,7 @@ HRESULT create_view( const struct property *, const WCHAR *, const struct expr * ...@@ -163,6 +164,7 @@ HRESULT create_view( const struct property *, const WCHAR *, const struct expr *
void destroy_view( struct view * ) DECLSPEC_HIDDEN; void destroy_view( struct view * ) DECLSPEC_HIDDEN;
void init_table_list( void ) DECLSPEC_HIDDEN; void init_table_list( void ) DECLSPEC_HIDDEN;
struct table *grab_table( const WCHAR * ) DECLSPEC_HIDDEN; struct table *grab_table( const WCHAR * ) DECLSPEC_HIDDEN;
struct table *addref_table( struct table * ) DECLSPEC_HIDDEN;
void release_table( struct table * ) DECLSPEC_HIDDEN; void release_table( struct table * ) DECLSPEC_HIDDEN;
struct table *create_table( const WCHAR *, UINT, const struct column *, UINT, struct table *create_table( const WCHAR *, UINT, const struct column *, UINT,
BYTE *, void (*)(struct table *)) DECLSPEC_HIDDEN; BYTE *, void (*)(struct table *)) DECLSPEC_HIDDEN;
......
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