From 4f603c718dd45a632b7036f5977c819bfbb36c8a Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Tue, 20 Mar 2012 10:08:37 +0000 Subject: [PATCH] Fix crash/invalid memory access when unposting an invoice. This is triggered when glib is configured with G_SLICE=always-malloc git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22104 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/gncInvoice.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/engine/gncInvoice.c b/src/engine/gncInvoice.c index 90eadcb4bd..2b5628cd37 100644 --- a/src/engine/gncInvoice.c +++ b/src/engine/gncInvoice.c @@ -1532,7 +1532,10 @@ gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables) * You could consider these transactions to be links between lots as well, but * to avoid some unexpected behavior, these will not be altered here. */ - lot_split_list = gnc_lot_get_split_list (lot); + + // Note: make a copy of the lot list here, when splits are deleted from the lot, + // the original list may be destroyed by the lot code. + lot_split_list = g_list_copy (gnc_lot_get_split_list (lot)); for (lot_split_iter = lot_split_list; lot_split_iter; lot_split_iter = lot_split_iter->next) { Split *split = lot_split_iter->data; @@ -1566,7 +1569,6 @@ gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables) xaccTransBeginEdit (other_txn); xaccTransDestroy (other_txn); xaccTransCommitEdit (other_txn); - g_assert(lot_split_list == gnc_lot_get_split_list (lot)); /* Re-balance the saved lots as well as is possible */ gncOwnerAutoApplyPaymentsWithLots (&invoice->owner, lot_list); @@ -1585,6 +1587,7 @@ gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables) qof_event_gen (QOF_INSTANCE(other_invoice), QOF_EVENT_MODIFY, NULL); } } + g_list_free (lot_split_list); /* If the lot has no splits, then destroy it */ if (!gnc_lot_count_splits (lot))