From 6a9ff287cddf1bee55c5d05331e0487372347151 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sat, 14 Aug 2021 11:01:38 +0100 Subject: [PATCH] Wrap BillTermDecRef and TaxTableDecRef in test for shutdown When Gnucash is shutting down, the TaxTables and BillTerms will be destroyed/freed and may already have been so there is no point trying to decrement a reference that is used to stop them being destroyed if in use. --- libgnucash/engine/gncCustomer.c | 9 +++++---- libgnucash/engine/gncEntry.c | 12 ++++++++---- libgnucash/engine/gncInvoice.c | 10 +++++++--- libgnucash/engine/gncVendor.c | 11 +++++++---- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/libgnucash/engine/gncCustomer.c b/libgnucash/engine/gncCustomer.c index 2ce39c8cce..676a7ed4cc 100644 --- a/libgnucash/engine/gncCustomer.c +++ b/libgnucash/engine/gncCustomer.c @@ -358,11 +358,12 @@ static void gncCustomerFree (GncCustomer *cust) g_list_free (cust->jobs); g_free (cust->balance); - if (cust->terms) - gncBillTermDecRef (cust->terms); - if (cust->taxtable) + if (!qof_book_shutting_down (qof_instance_get_book (QOF_INSTANCE(cust)))) { - gncTaxTableDecRef (cust->taxtable); + if (cust->terms) + gncBillTermDecRef (cust->terms); + if (cust->taxtable) + gncTaxTableDecRef (cust->taxtable); } /* qof_instance_release (&cust->inst); */ diff --git a/libgnucash/engine/gncEntry.c b/libgnucash/engine/gncEntry.c index b967544638..9d813d2e57 100644 --- a/libgnucash/engine/gncEntry.c +++ b/libgnucash/engine/gncEntry.c @@ -462,10 +462,14 @@ static void gncEntryFree (GncEntry *entry) gncAccountValueDestroy (entry->i_tax_values); if (entry->b_tax_values) gncAccountValueDestroy (entry->b_tax_values); - if (entry->i_tax_table) - gncTaxTableDecRef (entry->i_tax_table); - if (entry->b_tax_table) - gncTaxTableDecRef (entry->b_tax_table); + + if (!qof_book_shutting_down (qof_instance_get_book (QOF_INSTANCE(entry)))) + { + if (entry->i_tax_table) + gncTaxTableDecRef (entry->i_tax_table); + if (entry->b_tax_table) + gncTaxTableDecRef (entry->b_tax_table); + } /* qof_instance_release (&entry->inst); */ g_object_unref (entry); diff --git a/libgnucash/engine/gncInvoice.c b/libgnucash/engine/gncInvoice.c index 6ab155f813..ca9246136e 100644 --- a/libgnucash/engine/gncInvoice.c +++ b/libgnucash/engine/gncInvoice.c @@ -423,10 +423,14 @@ static void gncInvoiceFree (GncInvoice *invoice) g_list_free (invoice->entries); g_list_free (invoice->prices); - if (invoice->printname) g_free (invoice->printname); + if (invoice->printname) + g_free (invoice->printname); - if (invoice->terms) - gncBillTermDecRef (invoice->terms); + if (!qof_book_shutting_down (qof_instance_get_book (QOF_INSTANCE(invoice)))) + { + if (invoice->terms) + gncBillTermDecRef (invoice->terms); + } /* qof_instance_release (&invoice->inst); */ g_object_unref (invoice); diff --git a/libgnucash/engine/gncVendor.c b/libgnucash/engine/gncVendor.c index 50695de27d..1fa0a34100 100644 --- a/libgnucash/engine/gncVendor.c +++ b/libgnucash/engine/gncVendor.c @@ -501,10 +501,13 @@ static void gncVendorFree (GncVendor *vendor) g_list_free (vendor->jobs); g_free (vendor->balance); - if (vendor->terms) - gncBillTermDecRef (vendor->terms); - if (vendor->taxtable) - gncTaxTableDecRef (vendor->taxtable); + if (!qof_book_shutting_down (qof_instance_get_book (QOF_INSTANCE(vendor)))) + { + if (vendor->terms) + gncBillTermDecRef (vendor->terms); + if (vendor->taxtable) + gncTaxTableDecRef (vendor->taxtable); + } /* qof_instance_release (&vendor->inst); */ g_object_unref (vendor);