Module: wine Branch: master Commit: 2eb666d624d3729f25b8bc9a5f51be7e95d71829 URL: http://source.winehq.org/git/wine.git/?a=commit;h=2eb666d624d3729f25b8bc9a5f...
Author: Hans Leidekker hans@codeweavers.com Date: Wed Oct 17 11:06:41 2012 +0200
wbemprox: Keep a reference to the table from uncommitted instances.
---
dlls/wbemprox/class.c | 32 ++++++++++++-------------------- dlls/wbemprox/query.c | 3 ++- dlls/wbemprox/table.c | 9 +++++++-- dlls/wbemprox/wbemprox_private.h | 4 +++- 4 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/dlls/wbemprox/class.c b/dlls/wbemprox/class.c index dc03371..a3a06e1 100644 --- a/dlls/wbemprox/class.c +++ b/dlls/wbemprox/class.c @@ -202,8 +202,7 @@ HRESULT EnumWbemClassObject_create(
ec->IEnumWbemClassObject_iface.lpVtbl = &enum_class_object_vtbl; ec->refs = 1; - ec->query = query; - addref_query( query ); + ec->query = addref_query( query ); ec->index = 0;
*ppObj = &ec->IEnumWbemClassObject_iface; @@ -212,24 +211,25 @@ HRESULT EnumWbemClassObject_create( 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; struct record *record;
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 ); 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].vartype = columns[i].vartype; + record->fields[i].type = table->columns[i].type; + record->fields[i].vartype = table->columns[i].vartype; record->fields[i].u.ival = 0; } - record->count = num_cols; + record->count = table->num_cols; + record->table = addref_table( table ); return record; }
@@ -252,6 +252,7 @@ static void destroy_record( struct record *record ) UINT i;
if (!record) return; + release_table( record->table ); for (i = 0; i < record->count; i++) { if (record->fields[i].type == CIM_STRING || record->fields[i].type == CIM_DATETIME) @@ -390,14 +391,10 @@ static HRESULT WINAPI class_object_Get(
if (co->record) { - struct table *table = grab_table( co->name ); UINT index; HRESULT hr;
- if (!table) return WBEM_E_FAILED; - hr = get_column_index( table, wszName, &index ); - release_table( table ); - if (hr != S_OK) return hr; + if ((hr = get_column_index( co->record->table, wszName, &index )) != S_OK) return hr; return record_get_value( co->record, index, pVal, pType ); } return get_propval( ec->query->view, co->index, wszName, pVal, pType, plFlavor ); @@ -450,14 +447,10 @@ static HRESULT WINAPI class_object_Put(
if (co->record) { - struct table *table = grab_table( co->name ); UINT index; HRESULT hr;
- if (!table) return WBEM_E_FAILED; - hr = get_column_index( table, wszName, &index ); - release_table( table ); - if (hr != S_OK) return hr; + if ((hr = get_column_index( co->record->table, wszName, &index )) != S_OK) return hr; return record_set_value( co->record, index, pVal ); } return put_propval( ec->query->view, co->index, wszName, pVal, Type ); @@ -650,8 +643,7 @@ static HRESULT WINAPI class_object_SpawnInstance(
TRACE("%p, %08x, %p\n", iface, lFlags, ppNewInstance);
- if (!(record = create_record( view->table->columns, view->table->num_cols ))) - return E_OUTOFMEMORY; + if (!(record = create_record( view->table ))) return E_OUTOFMEMORY;
return create_class_object( co->name, NULL, 0, record, ppNewInstance ); } diff --git a/dlls/wbemprox/query.c b/dlls/wbemprox/query.c index 29026c9..3fdee00 100644 --- a/dlls/wbemprox/query.c +++ b/dlls/wbemprox/query.c @@ -290,9 +290,10 @@ static void free_query( struct query *query ) heap_free( query ); }
-void addref_query( struct query *query ) +struct query *addref_query( struct query *query ) { InterlockedIncrement( &query->refs ); + return query; }
void release_query( struct query *query ) diff --git a/dlls/wbemprox/table.c b/dlls/wbemprox/table.c index 277998b..43ab91d 100644 --- a/dlls/wbemprox/table.c +++ b/dlls/wbemprox/table.c @@ -321,6 +321,12 @@ void release_table( struct 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 *table; @@ -330,9 +336,8 @@ struct table *grab_table( const WCHAR *name ) if (!strcmpiW( table->name, name )) { if (table->fill && !table->data) table->fill( table ); - InterlockedIncrement( &table->refs ); TRACE("returning %p\n", table); - return table; + return addref_table( table ); } } return NULL; diff --git a/dlls/wbemprox/wbemprox_private.h b/dlls/wbemprox/wbemprox_private.h index 02fc919..05da3c6 100644 --- a/dlls/wbemprox/wbemprox_private.h +++ b/dlls/wbemprox/wbemprox_private.h @@ -91,6 +91,7 @@ struct record { UINT count; struct field *fields; + struct table *table; };
enum operator @@ -154,7 +155,7 @@ struct query 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; HRESULT exec_query( const WCHAR *, IEnumWbemClassObject ** ) 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 * void destroy_view( struct view * ) DECLSPEC_HIDDEN; void init_table_list( void ) 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; struct table *create_table( const WCHAR *, UINT, const struct column *, UINT, BYTE *, void (*)(struct table *)) DECLSPEC_HIDDEN;