r19984 - gnucash/trunk/src/backend/sql - Plug some memory leaks

Phil Longstaff plongstaff at code.gnucash.org
Tue Dec 28 15:44:25 EST 2010


Author: plongstaff
Date: 2010-12-28 15:44:25 -0500 (Tue, 28 Dec 2010)
New Revision: 19984
Trac: http://svn.gnucash.org/trac/changeset/19984

Modified:
   gnucash/trunk/src/backend/sql/gnc-account-sql.c
   gnucash/trunk/src/backend/sql/gnc-bill-term-sql.c
   gnucash/trunk/src/backend/sql/gnc-customer-sql.c
   gnucash/trunk/src/backend/sql/gnc-employee-sql.c
   gnucash/trunk/src/backend/sql/gnc-entry-sql.c
   gnucash/trunk/src/backend/sql/gnc-invoice-sql.c
   gnucash/trunk/src/backend/sql/gnc-job-sql.c
   gnucash/trunk/src/backend/sql/gnc-order-sql.c
   gnucash/trunk/src/backend/sql/gnc-slots-sql.c
   gnucash/trunk/src/backend/sql/gnc-vendor-sql.c
Log:
Plug some memory leaks


Modified: gnucash/trunk/src/backend/sql/gnc-account-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-account-sql.c	2010-12-27 21:07:58 UTC (rev 19983)
+++ gnucash/trunk/src/backend/sql/gnc-account-sql.c	2010-12-28 20:44:25 UTC (rev 19984)
@@ -253,28 +253,39 @@
             while ( progress_made )
             {
                 progress_made = FALSE;
-                for ( elem = l_accounts_needing_parents; elem != NULL; elem = g_list_next( elem ) )
+                for ( elem = l_accounts_needing_parents; elem != NULL; )
                 {
                     account_parent_guid_struct* s = (account_parent_guid_struct*)elem->data;
                     pParent = xaccAccountLookup( &s->guid, be->primary_book );
                     if ( pParent != NULL )
                     {
+                        GList* next_elem;
+
                         gnc_account_append_child( pParent, s->pAccount );
+                        next_elem = g_list_next( elem );
                         l_accounts_needing_parents = g_list_delete_link( l_accounts_needing_parents, elem );
+                        elem = next_elem;
                         progress_made = TRUE;
                     }
+                    else
+                    {
+                        /* Can't be up in the for loop because the 'then' clause reads inside a node freed
+                           by g_list_delete_link(). */
+                        elem = g_list_next( elem );
+                    }
                 }
             }
 
             /* Any non-ROOT accounts left over must be parented by the root account */
             root = gnc_book_get_root_account( pBook );
-            for ( elem = l_accounts_needing_parents; elem != NULL; elem = g_list_next( elem ) )
+            while ( l_accounts_needing_parents != NULL )
             {
-                account_parent_guid_struct* s = (account_parent_guid_struct*)elem->data;
+                account_parent_guid_struct* s = (account_parent_guid_struct*)l_accounts_needing_parents->data;
                 if ( xaccAccountGetType( s->pAccount ) != ACCT_TYPE_ROOT )
                 {
                     gnc_account_append_child( root, s->pAccount );
                 }
+                l_accounts_needing_parents = g_list_delete_link( l_accounts_needing_parents, l_accounts_needing_parents );
             }
         }
 

Modified: gnucash/trunk/src/backend/sql/gnc-bill-term-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-bill-term-sql.c	2010-12-27 21:07:58 UTC (rev 19983)
+++ gnucash/trunk/src/backend/sql/gnc-bill-term-sql.c	2010-12-28 20:44:25 UTC (rev 19984)
@@ -255,6 +255,7 @@
         if ( list != NULL )
         {
             gnc_sql_slots_load_for_list( be, list );
+            g_list_free( list );
         }
 
         /* While there are items on the list of billterms needing parents,

Modified: gnucash/trunk/src/backend/sql/gnc-customer-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-customer-sql.c	2010-12-27 21:07:58 UTC (rev 19983)
+++ gnucash/trunk/src/backend/sql/gnc-customer-sql.c	2010-12-28 20:44:25 UTC (rev 19984)
@@ -139,6 +139,7 @@
         if ( list != NULL )
         {
             gnc_sql_slots_load_for_list( be, list );
+            g_list_free( list );
         }
     }
 }

Modified: gnucash/trunk/src/backend/sql/gnc-employee-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-employee-sql.c	2010-12-27 21:07:58 UTC (rev 19983)
+++ gnucash/trunk/src/backend/sql/gnc-employee-sql.c	2010-12-28 20:44:25 UTC (rev 19984)
@@ -132,6 +132,7 @@
         if ( list != NULL )
         {
             gnc_sql_slots_load_for_list( be, list );
+            g_list_free( list );
         }
     }
 }

Modified: gnucash/trunk/src/backend/sql/gnc-entry-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-entry-sql.c	2010-12-27 21:07:58 UTC (rev 19983)
+++ gnucash/trunk/src/backend/sql/gnc-entry-sql.c	2010-12-28 20:44:25 UTC (rev 19984)
@@ -204,6 +204,7 @@
         if ( list != NULL )
         {
             gnc_sql_slots_load_for_list( be, list );
+            g_list_free( list );
         }
     }
 }

Modified: gnucash/trunk/src/backend/sql/gnc-invoice-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-invoice-sql.c	2010-12-27 21:07:58 UTC (rev 19983)
+++ gnucash/trunk/src/backend/sql/gnc-invoice-sql.c	2010-12-28 20:44:25 UTC (rev 19984)
@@ -147,6 +147,7 @@
         if ( list != NULL )
         {
             gnc_sql_slots_load_for_list( be, list );
+            g_list_free( list );
         }
     }
 }

Modified: gnucash/trunk/src/backend/sql/gnc-job-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-job-sql.c	2010-12-27 21:07:58 UTC (rev 19983)
+++ gnucash/trunk/src/backend/sql/gnc-job-sql.c	2010-12-28 20:44:25 UTC (rev 19984)
@@ -124,6 +124,7 @@
         if ( list != NULL )
         {
             gnc_sql_slots_load_for_list( be, list );
+            g_list_free( list );
         }
     }
 }

Modified: gnucash/trunk/src/backend/sql/gnc-order-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-order-sql.c	2010-12-27 21:07:58 UTC (rev 19983)
+++ gnucash/trunk/src/backend/sql/gnc-order-sql.c	2010-12-28 20:44:25 UTC (rev 19984)
@@ -121,6 +121,7 @@
         if ( list != NULL )
         {
             gnc_sql_slots_load_for_list( be, list );
+            g_list_free( list );
         }
     }
 }

Modified: gnucash/trunk/src/backend/sql/gnc-slots-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-slots-sql.c	2010-12-27 21:07:58 UTC (rev 19983)
+++ gnucash/trunk/src/backend/sql/gnc-slots-sql.c	2010-12-28 20:44:25 UTC (rev 19984)
@@ -183,7 +183,9 @@
 get_key_from_path( GString *path )
 {
     gchar *str = NULL, *key = NULL, *ret = NULL;
+
     g_return_val_if_fail( path != NULL, strdup("") );
+
     if ( path->str == NULL ) return strdup("");
     str = g_strdup( path->str );
     key = strrchr( str, '/');
@@ -208,7 +210,9 @@
 get_path_from_path( GString *path )
 {
     gchar *str = NULL, *key = NULL, *ret = NULL;
+
     g_return_val_if_fail( path != NULL, NULL );
+
     if ( path->str == NULL ) return NULL;
     str = g_strdup( path->str );
     key = strrchr( str, '/');
@@ -240,6 +244,7 @@
 {
     g_return_if_fail( pInfo != NULL );
     g_return_if_fail( pValue != NULL );
+
     switch ( pInfo->context)
     {
     case FRAME:
@@ -613,8 +618,7 @@
     newSlot->pList = pInfo->pList;
     newSlot->context = pInfo->context;
     newSlot->pKvpValue = pInfo->pKvpValue;
-    newSlot->path = g_string_new('\0');
-    g_string_assign( newSlot->path, pInfo->path->str);
+    newSlot->path = g_string_new(pInfo->path->str);
     return newSlot;
 }
 
@@ -873,7 +877,7 @@
 static void
 load_slot_for_list_item( GncSqlBackend* be, GncSqlRow* row, QofCollection* coll )
 {
-    slot_info_t slot_info = { NULL, NULL, TRUE, NULL, 0, NULL, FRAME, NULL, g_string_new('\0') };
+    slot_info_t slot_info = { NULL, NULL, TRUE, NULL, 0, NULL, FRAME, NULL, NULL };
     const GncGUID* guid;
     QofInstance* inst;
 
@@ -887,7 +891,6 @@
 
     slot_info.be = be;
     slot_info.pKvpFrame = qof_instance_get_slots( inst );
-    slot_info.path = NULL;
     slot_info.context = NONE;
 
     gnc_sql_load_object( be, row, TABLE_NAME, &slot_info, col_table );
@@ -960,7 +963,7 @@
 static void
 load_slot_for_book_object( GncSqlBackend* be, GncSqlRow* row, BookLookupFn lookup_fn )
 {
-    slot_info_t slot_info = { NULL, NULL, TRUE, NULL, 0, NULL, FRAME, NULL, g_string_new('\0') };
+    slot_info_t slot_info = { NULL, NULL, TRUE, NULL, 0, NULL, FRAME, NULL, NULL };
     const GncGUID* guid;
     QofInstance* inst;
 

Modified: gnucash/trunk/src/backend/sql/gnc-vendor-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-vendor-sql.c	2010-12-27 21:07:58 UTC (rev 19983)
+++ gnucash/trunk/src/backend/sql/gnc-vendor-sql.c	2010-12-28 20:44:25 UTC (rev 19984)
@@ -138,6 +138,7 @@
         if ( list != NULL )
         {
             gnc_sql_slots_load_for_list( be, list );
+            g_list_free( list );
         }
     }
 }



More information about the gnucash-changes mailing list