From 744e22c7df9eb21d32e693927e20260ef8d8fced Mon Sep 17 00:00:00 2001 From: Mike McCormack Date: Mon, 26 Sep 2005 10:55:18 +0000 Subject: [PATCH] Fix various query related memory leaks. --- dlls/msi/package.c | 14 +++++--------- dlls/msi/select.c | 12 +++++------- dlls/msi/sql.y | 32 +++++++++++++++++++++----------- dlls/msi/update.c | 6 ++---- dlls/msi/where.c | 4 +++- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/dlls/msi/package.c b/dlls/msi/package.c index f37beeaa2bc..b37ce4de1c6 100644 --- a/dlls/msi/package.c +++ b/dlls/msi/package.c @@ -757,19 +757,15 @@ UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue) MSI_RecordSetStringW(row,2,szValue); } - rc = MSI_DatabaseOpenViewW(package->db,Query,&view); - if (rc!= ERROR_SUCCESS) + if (rc == ERROR_SUCCESS) { - msiobj_release(&row->hdr); - return rc; + rc = MSI_ViewExecute(view,row); + + MSI_ViewClose(view); + msiobj_release(&view->hdr); } - - rc = MSI_ViewExecute(view,row); - msiobj_release(&row->hdr); - MSI_ViewClose(view); - msiobj_release(&view->hdr); return rc; } diff --git a/dlls/msi/select.c b/dlls/msi/select.c index ae4bc6cb7d2..7345c1777fa 100644 --- a/dlls/msi/select.c +++ b/dlls/msi/select.c @@ -189,6 +189,7 @@ static UINT SELECT_delete( struct tagMSIVIEW *view ) if( sv->table ) sv->table->ops->delete( sv->table ); + sv->table = NULL; msi_free( sv ); @@ -278,13 +279,10 @@ UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table, columns = columns->next; } - if( r != ERROR_SUCCESS ) - { - sv->view.ops->delete( &sv->view ); - sv = NULL; - } - - *view = &sv->view; + if( r == ERROR_SUCCESS ) + *view = &sv->view; + else + msi_free( sv ); return r; } diff --git a/dlls/msi/sql.y b/dlls/msi/sql.y index 97fe0111903..1bdc82aa9bb 100644 --- a/dlls/msi/sql.y +++ b/dlls/msi/sql.y @@ -349,11 +349,15 @@ unorderedsel: | TK_SELECT TK_DISTINCT selectfrom { SQL_input* sql = (SQL_input*) info; + UINT r; $$ = NULL; - DISTINCT_CreateView( sql->db, &$$, $3 ); - if( !$$ ) + r = DISTINCT_CreateView( sql->db, &$$, $3 ); + if (r != ERROR_SUCCESS) + { + $3->ops->delete($3); YYABORT; + } } ; @@ -361,15 +365,20 @@ selectfrom: selcollist from { SQL_input* sql = (SQL_input*) info; + UINT r; $$ = NULL; if( $1 ) - SELECT_CreateView( sql->db, &$$, $2, $1 ); + { + r = SELECT_CreateView( sql->db, &$$, $2, $1 ); + if (r != ERROR_SUCCESS) + { + $2->ops->delete($2); + YYABORT; + } + } else $$ = $2; - - if( !$$ ) - YYABORT; } ; @@ -394,8 +403,11 @@ from: $$ = NULL; r = WHERE_CreateView( sql->db, &$$, $1, $3 ); - if( r != ERROR_SUCCESS || !$$ ) + if( r != ERROR_SUCCESS ) + { + $1->ops->delete( $1 ); YYABORT; + } } ; @@ -641,7 +653,7 @@ int SQL_lex( void *SQL_lval, SQL_input *sql ) if( ! sql->command[sql->n] ) return 0; /* end of input */ - TRACE("string : %s\n", debugstr_w(&sql->command[sql->n])); + /* TRACE("string : %s\n", debugstr_w(&sql->command[sql->n])); */ sql->len = sqliteGetToken( &sql->command[sql->n], &token ); if( sql->len==0 ) break; @@ -650,7 +662,7 @@ int SQL_lex( void *SQL_lval, SQL_input *sql ) } while( token == TK_SPACE ); - TRACE("token : %d (%s)\n", token, debugstr_wn(&sql->command[sql->n], sql->len)); + /* TRACE("token : %d (%s)\n", token, debugstr_wn(&sql->command[sql->n], sql->len)); */ return token; } @@ -800,8 +812,6 @@ UINT MSI_ParseSQL( MSIDATABASE *db, LPCWSTR command, MSIVIEW **phview, TRACE("Parse returned %d\n", r); if( r ) { - if( *sql.view ) - (*sql.view)->ops->delete( *sql.view ); *sql.view = NULL; return ERROR_BAD_QUERY_SYNTAX; } diff --git a/dlls/msi/update.c b/dlls/msi/update.c index 0971982c9f5..6a5791297a0 100644 --- a/dlls/msi/update.c +++ b/dlls/msi/update.c @@ -209,8 +209,7 @@ UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table, r = WHERE_CreateView( db, &wv, tv, expr ); if( r != ERROR_SUCCESS ) { - if( sv ) - sv->ops->delete( tv ); + tv->ops->delete( tv ); return r; } @@ -218,8 +217,7 @@ UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table, r = SELECT_CreateView( db, &sv, wv, columns ); if( r != ERROR_SUCCESS ) { - if( tv ) - tv->ops->delete( sv ); + wv->ops->delete( wv ); return r; } diff --git a/dlls/msi/where.c b/dlls/msi/where.c index 2602b1838a8..cf54e4a05af 100644 --- a/dlls/msi/where.c +++ b/dlls/msi/where.c @@ -242,6 +242,7 @@ static UINT WHERE_execute( struct tagMSIVIEW *view, MSIRECORD *record ) if( r != ERROR_SUCCESS ) return r; + msi_free( wv->reorder ); wv->reorder = msi_alloc( count*sizeof(UINT) ); if( !wv->reorder ) return ERROR_FUNCTION_FAILED; @@ -328,6 +329,7 @@ static UINT WHERE_delete( struct tagMSIVIEW *view ) if( wv->table ) wv->table->ops->delete( wv->table ); + wv->table = 0; msi_free( wv->reorder ); wv->reorder = NULL; @@ -444,7 +446,7 @@ UINT WHERE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table, MSIWHEREVIEW *wv = NULL; UINT count = 0, r, valid = 0; - TRACE("%p\n", wv ); + TRACE("%p\n", table ); r = table->ops->get_dimensions( table, NULL, &count ); if( r != ERROR_SUCCESS )