From af2e6b3fa4cbc3815afc559507b6ca13ea297591 Mon Sep 17 00:00:00 2001 From: Phil Longstaff Date: Wed, 29 Dec 2010 01:43:28 +0000 Subject: [PATCH] When a book is closed, all of the memory for the objects should be freed. Free budgets and invoices. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19987 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/gnc-budget.c | 23 ++++++++++++++++++++++- src/engine/gncInvoice.c | 20 +++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/engine/gnc-budget.c b/src/engine/gnc-budget.c index dc78c5067e..db30a83f53 100644 --- a/src/engine/gnc-budget.c +++ b/src/engine/gnc-budget.c @@ -635,6 +635,27 @@ gnc_budget_get_default (QofBook *book) 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 @@ static QofObject budget_object_def = 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, diff --git a/src/engine/gncInvoice.c b/src/engine/gncInvoice.c index 5c490fa8a4..5fb08afd59 100644 --- a/src/engine/gncInvoice.c +++ b/src/engine/gncInvoice.c @@ -2014,6 +2014,24 @@ static const char * _gncInvoicePrintable (gpointer obj) 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 @@ static QofObject gncInvoiceDesc = 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,