From 0eb9d7139c8b1ab8d1133a598ccfdd31bfee2a4f Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Tue, 10 Jun 2003 04:38:10 +0000 Subject: [PATCH] ongoing fixes git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8534 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Group.c | 12 ++---------- src/engine/SchedXaction.c | 7 +++++++ src/engine/gnc-book.c | 9 +-------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/engine/Group.c b/src/engine/Group.c index bc28cebc7c..03560fadce 100644 --- a/src/engine/Group.c +++ b/src/engine/Group.c @@ -106,16 +106,8 @@ xaccSetAccountGroup (GNCBook *book, AccountGroup *grp) gnc_book_set_data (book, GNC_TOP_GROUP, grp); - /* XXX Do not free the old topgroup here unless you also fix - * all the other uses of xaccSetAccountGroup()! That's because - * the account group is not reference-counted, and there's some - * chance that we'll leave a dangling pointer somewhere. - */ - - /* - xaccAccountGroupBeginEdit (old_grp); - xaccAccountGroupDestroy (old_grp); - */ + xaccAccountGroupBeginEdit (old_grp); + xaccAccountGroupDestroy (old_grp); } /********************************************************************\ diff --git a/src/engine/SchedXaction.c b/src/engine/SchedXaction.c index 3104ca0d26..0295d07a9a 100644 --- a/src/engine/SchedXaction.c +++ b/src/engine/SchedXaction.c @@ -803,6 +803,7 @@ gnc_book_get_template_group( GNCBook *book ) void gnc_book_set_template_group (GNCBook *book, AccountGroup *templateGroup) { + AccountGroup *old_grp; if (!book) return; if (templateGroup && templateGroup->book != book) @@ -811,6 +812,12 @@ gnc_book_set_template_group (GNCBook *book, AccountGroup *templateGroup) return; } + old_grp = gnc_book_get_template_group (book); + if (old_grp == templateGroup) return; + gnc_book_set_data (book, GNC_TEMPLATE_GROUP, templateGroup); + + xaccAccountGroupBeginEdit (old_grp); + xaccAccountGroupDestroy (old_grp); } diff --git a/src/engine/gnc-book.c b/src/engine/gnc-book.c index 7ab81290d7..774a53f09b 100644 --- a/src/engine/gnc-book.c +++ b/src/engine/gnc-book.c @@ -169,22 +169,15 @@ gnc_book_populate (GNCBook *book) static void gnc_book_depopulate (GNCBook *book) { - AccountGroup *grp; - gnc_commodity_table *ct; - /* unhook the top-level group */ - grp = xaccGetAccountGroup (book); - xaccAccountGroupBeginEdit (grp); - xaccAccountGroupDestroy (grp); xaccSetAccountGroup (book, NULL); /* unhook the prices */ gnc_pricedb_set_db (book, NULL); - ct = gnc_commodity_table_get_table (book); - gnc_commodity_table_destroy (ct); gnc_commodity_table_set_table (book, NULL); + gnc_book_set_template_group (book, NULL); /* FIXME: destroy SX data members here, too */ }