Fix various query related memory leaks.
authorMike McCormack <mike@codeweavers.com>
Mon, 26 Sep 2005 10:55:18 +0000 (10:55 +0000)
committerAlexandre Julliard <julliard@winehq.org>
Mon, 26 Sep 2005 10:55:18 +0000 (10:55 +0000)
dlls/msi/package.c
dlls/msi/select.c
dlls/msi/sql.y
dlls/msi/update.c
dlls/msi/where.c

index f37beea..b37ce4d 100644 (file)
@@ -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);
+        rc = MSI_ViewExecute(view,row);
 
+        MSI_ViewClose(view);
+        msiobj_release(&view->hdr);
+    }
     msiobj_release(&row->hdr);
-    MSI_ViewClose(view);
-    msiobj_release(&view->hdr);
 
     return rc;
 }
index ae4bc6c..7345c17 100644 (file)
@@ -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;
 }
index 97fe011..1bdc82a 100644 (file)
@@ -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;
     }
index 0971982..6a57912 100644 (file)
@@ -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;
     }
 
index 2602b18..cf54e4a 100644 (file)
@@ -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 )