Commit 9015eebf authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

wbemprox: Protect tables with a critical section.

parent ce6e298a
...@@ -236,7 +236,7 @@ static struct record *create_record( struct table *table ) ...@@ -236,7 +236,7 @@ static struct record *create_record( struct table *table )
record->fields[i].u.ival = 0; record->fields[i].u.ival = 0;
} }
record->count = table->num_cols; record->count = table->num_cols;
record->table = addref_table( table ); record->table = grab_table( table );
return record; return record;
} }
......
...@@ -54,11 +54,12 @@ HRESULT create_view( enum view_type type, enum wbm_namespace ns, const WCHAR *pa ...@@ -54,11 +54,12 @@ HRESULT create_view( enum view_type type, enum wbm_namespace ns, const WCHAR *pa
case VIEW_TYPE_SELECT: case VIEW_TYPE_SELECT:
{ {
struct table *table = grab_table( ns, class ); struct table *table = find_table( ns, class );
HRESULT hr; HRESULT hr;
if (table && (hr = append_table( view, table )) != S_OK) if (table && (hr = append_table( view, table )) != S_OK)
{ {
release_table( table );
free( view ); free( view );
return hr; return hr;
} }
...@@ -631,7 +632,7 @@ static HRESULT get_antecedent_table( enum wbm_namespace ns, const WCHAR *assoccl ...@@ -631,7 +632,7 @@ static HRESULT get_antecedent_table( enum wbm_namespace ns, const WCHAR *assoccl
} }
if ((hr = do_query( ns, str, &query )) != S_OK) goto done; if ((hr = do_query( ns, str, &query )) != S_OK) goto done;
if (query->view->table_count) *table = addref_table( query->view->table[0] ); if (query->view->table_count) *table = grab_table( query->view->table[0] );
else *table = NULL; else *table = NULL;
done: done:
......
...@@ -29,6 +29,15 @@ ...@@ -29,6 +29,15 @@
WINE_DEFAULT_DEBUG_CHANNEL(wbemprox); WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
static CRITICAL_SECTION table_cs;
static CRITICAL_SECTION_DEBUG table_debug =
{
0, 0, &table_cs,
{ &table_debug.ProcessLocksList, &table_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": table_cs") }
};
static CRITICAL_SECTION table_cs = { &table_debug, -1, 0, 0, 0, 0 };
HRESULT get_column_index( const struct table *table, const WCHAR *name, UINT *column ) HRESULT get_column_index( const struct table *table, const WCHAR *name, UINT *column )
{ {
UINT i; UINT i;
...@@ -329,6 +338,7 @@ void free_table( struct table *table ) ...@@ -329,6 +338,7 @@ void free_table( struct table *table )
{ {
if (!table) return; if (!table) return;
EnterCriticalSection( &table_cs );
clear_table( table ); clear_table( table );
if (table->flags & TABLE_FLAG_DYNAMIC) if (table->flags & TABLE_FLAG_DYNAMIC)
{ {
...@@ -339,20 +349,23 @@ void free_table( struct table *table ) ...@@ -339,20 +349,23 @@ void free_table( struct table *table )
list_remove( &table->entry ); list_remove( &table->entry );
free( table ); free( table );
} }
LeaveCriticalSection( &table_cs );
} }
void release_table( struct table *table ) void release_table( struct table *table )
{ {
if (!InterlockedDecrement( &table->refs )) free_table( table ); if (!InterlockedDecrement( &table->refs )) free_table( table );
LeaveCriticalSection( &table_cs );
} }
struct table *addref_table( struct table *table ) struct table *grab_table( struct table *table )
{ {
EnterCriticalSection( &table_cs );
InterlockedIncrement( &table->refs ); InterlockedIncrement( &table->refs );
return table; return table;
} }
struct table *grab_table( enum wbm_namespace ns, const WCHAR *name ) struct table *find_table( enum wbm_namespace ns, const WCHAR *name )
{ {
struct table *table; struct table *table;
...@@ -363,7 +376,7 @@ struct table *grab_table( enum wbm_namespace ns, const WCHAR *name ) ...@@ -363,7 +376,7 @@ struct table *grab_table( enum wbm_namespace ns, const WCHAR *name )
if (name && !wcsicmp( table->name, name )) if (name && !wcsicmp( table->name, name ))
{ {
TRACE("returning %p\n", table); TRACE("returning %p\n", table);
return addref_table( table ); return grab_table( table );
} }
} }
return NULL; return NULL;
...@@ -395,15 +408,19 @@ BOOL add_table( enum wbm_namespace ns, struct table *table ) ...@@ -395,15 +408,19 @@ BOOL add_table( enum wbm_namespace ns, struct table *table )
if (ns == WBEMPROX_NAMESPACE_LAST) return FALSE; if (ns == WBEMPROX_NAMESPACE_LAST) return FALSE;
EnterCriticalSection( &table_cs );
LIST_FOR_EACH_ENTRY( iter, table_list[ns], struct table, entry ) LIST_FOR_EACH_ENTRY( iter, table_list[ns], struct table, entry )
{ {
if (!wcsicmp( iter->name, table->name )) if (!wcsicmp( iter->name, table->name ))
{ {
TRACE("table %s already exists\n", debugstr_w(table->name)); TRACE("table %s already exists\n", debugstr_w(table->name));
LeaveCriticalSection( &table_cs );
return FALSE; return FALSE;
} }
} }
list_add_tail( table_list[ns], &table->entry ); list_add_tail( table_list[ns], &table->entry );
LeaveCriticalSection( &table_cs );
TRACE("added %p\n", table); TRACE("added %p\n", table);
return TRUE; return TRUE;
} }
...@@ -414,7 +431,7 @@ BSTR get_method_name( enum wbm_namespace ns, const WCHAR *class, UINT index ) ...@@ -414,7 +431,7 @@ BSTR get_method_name( enum wbm_namespace ns, const WCHAR *class, UINT index )
UINT i, count = 0; UINT i, count = 0;
BSTR ret; BSTR ret;
if (!(table = grab_table( ns, class ))) return NULL; if (!(table = find_table( ns, class ))) return NULL;
for (i = 0; i < table->num_cols; i++) for (i = 0; i < table->num_cols; i++)
{ {
......
...@@ -215,8 +215,8 @@ HRESULT execute_view( struct view * ); ...@@ -215,8 +215,8 @@ HRESULT execute_view( struct view * );
struct table *get_view_table( const struct view *, UINT ); struct table *get_view_table( const struct view *, UINT );
void init_table_list( void ); void init_table_list( void );
enum wbm_namespace get_namespace_from_string( const WCHAR *namespace ); enum wbm_namespace get_namespace_from_string( const WCHAR *namespace );
struct table *grab_table( enum wbm_namespace, const WCHAR * ); struct table *find_table( enum wbm_namespace, const WCHAR * );
struct table *addref_table( struct table * ); struct table *grab_table( struct table * );
void release_table( struct table * ); void release_table( struct table * );
struct table *create_table( const WCHAR *, UINT, const struct column *, UINT, UINT, BYTE *, struct table *create_table( const WCHAR *, UINT, const struct column *, UINT, UINT, BYTE *,
enum fill_status (*)(struct table *, const struct expr *) ); enum fill_status (*)(struct table *, 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