r19987 - gnucash/trunk/src/engine - When a book is closed, all of the memory for the objects should be freed.

Phil Longstaff plongstaff at code.gnucash.org
Tue Dec 28 20:43:28 EST 2010


Author: plongstaff
Date: 2010-12-28 20:43:28 -0500 (Tue, 28 Dec 2010)
New Revision: 19987
Trac: http://svn.gnucash.org/trac/changeset/19987

Modified:
   gnucash/trunk/src/engine/gnc-budget.c
   gnucash/trunk/src/engine/gncInvoice.c
Log:
When a book is closed, all of the memory for the objects should be freed.

Free budgets and invoices.


Modified: gnucash/trunk/src/engine/gnc-budget.c
===================================================================
--- gnucash/trunk/src/engine/gnc-budget.c	2010-12-29 01:39:49 UTC (rev 19986)
+++ gnucash/trunk/src/engine/gnc-budget.c	2010-12-29 01:43:28 UTC (rev 19987)
@@ -635,6 +635,27 @@
     return bgt;
 }
 
+static void
+destroy_budget_on_book_close(QofInstance *ent, gpointer data)
+{
+    GncBudget* bgt = GNC_BUDGET(ent);
+
+    gnc_budget_destroy(bgt);
+}
+
+/** Handles book end - frees all budgets from the book
+ *
+ * @param book Book being closed
+ */
+static void
+gnc_budget_book_end(QofBook* book)
+{
+    QofCollection *col;
+
+    col = qof_book_get_collection(book, GNC_ID_BUDGET);
+    qof_collection_foreach(col, destroy_budget_on_book_close, NULL);
+}
+
 #ifdef _MSC_VER
 /* MSVC compiler doesn't have C99 "designated initializers"
  * so we wrap them in a macro that is empty on MSVC. */
@@ -651,7 +672,7 @@
     DI(.type_label        = ) "Budget",
     DI(.create            = ) (gpointer)gnc_budget_new,
     DI(.book_begin        = ) NULL,
-    DI(.book_end          = ) NULL,
+    DI(.book_end          = ) gnc_budget_book_end,
     DI(.is_dirty          = ) qof_collection_is_dirty,
     DI(.mark_clean        = ) qof_collection_mark_clean,
     DI(.foreach           = ) qof_collection_foreach,

Modified: gnucash/trunk/src/engine/gncInvoice.c
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c	2010-12-29 01:39:49 UTC (rev 19986)
+++ gnucash/trunk/src/engine/gncInvoice.c	2010-12-29 01:43:28 UTC (rev 19987)
@@ -2014,6 +2014,24 @@
     return invoice->printname;
 }
 
+static void
+destroy_invoice_on_book_close(QofInstance *ent, gpointer data)
+{
+    GncInvoice* invoice = GNC_INVOICE(ent);
+
+    gncInvoiceBeginEdit(invoice);
+    gncInvoiceDestroy(invoice);
+}
+
+static void
+gnc_invoice_book_end(QofBook* book)
+{
+    QofCollection *col;
+
+    col = qof_book_get_collection(book, GNC_ID_INVOICE);
+    qof_collection_foreach(col, destroy_invoice_on_book_close, NULL);
+}
+
 static QofObject gncInvoiceDesc =
 {
     DI(.interface_version = ) QOF_OBJECT_VERSION,
@@ -2021,7 +2039,7 @@
     DI(.type_label        = ) "Invoice",
     DI(.create            = ) (gpointer)gncInvoiceCreate,
     DI(.book_begin        = ) NULL,
-    DI(.book_end          = ) NULL,
+    DI(.book_end          = ) gnc_invoice_book_end,
     DI(.is_dirty          = ) qof_collection_is_dirty,
     DI(.mark_clean        = ) qof_collection_mark_clean,
     DI(.foreach           = ) qof_collection_foreach,



More information about the gnucash-changes mailing list