gnucash stable: Bug 799272 - Crashes when pasting a copied transaction

John Ralls jralls at code.gnucash.org
Thu Apr 11 20:39:10 EDT 2024


Updated	 via  https://github.com/Gnucash/gnucash/commit/fafc745b (commit)
	from  https://github.com/Gnucash/gnucash/commit/8c94132f (commit)



commit fafc745b1b77dbbf01ff440f15ac6bab0215236a
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Apr 11 17:35:38 2024 -0700

    Bug 799272 - Crashes when pasting a copied transaction
    
    Clear the copied_item, copied_class, and copied_leader_guid on book
    close to ensure that they're not carried across sessions.

diff --git a/gnucash/register/ledger-core/split-register.c b/gnucash/register/ledger-core/split-register.c
index fef26495bd..95e008e3fc 100644
--- a/gnucash/register/ledger-core/split-register.c
+++ b/gnucash/register/ledger-core/split-register.c
@@ -35,6 +35,7 @@
 #include "gnc-component-manager.h"
 #include "split-register-p.h"
 #include "gnc-date.h"
+#include <gnc-hooks.h>
 #include "gnc-ledger-display.h"
 #include "gnc-prefs.h"
 #include "gnc-ui.h"
@@ -88,6 +89,19 @@ static gboolean gnc_split_register_auto_calc (SplitRegister *reg,
 
 /** implementations *******************************************************/
 
+static void
+clear_copied_item()
+{
+    if (copied_item.ftype == GNC_TYPE_SPLIT)
+        gnc_float_split_free (copied_item.fs);
+    if (copied_item.ftype == GNC_TYPE_TRANSACTION)
+        gnc_float_txn_free (copied_item.ft);
+    copied_item.ftype = 0;
+    copied_item.fs = NULL;
+    copied_class = CURSOR_CLASS_NONE;
+    copied_leader_guid = *guid_null();
+}
+
 static void
 gnc_copy_split_onto_split (Split* from, Split* to, gboolean use_cut_semantics)
 {
@@ -821,11 +835,7 @@ gnc_split_register_copy_current_internal (SplitRegister* reg,
     }
 
     /* unprotect the old object, if any */
-    if (copied_item.ftype == GNC_TYPE_SPLIT)
-        gnc_float_split_free (copied_item.fs);
-    if (copied_item.ftype == GNC_TYPE_TRANSACTION)
-        gnc_float_txn_free (copied_item.ft);
-    copied_item.ftype = 0;
+    clear_copied_item();
 
     if (new_fs)
     {
@@ -839,6 +849,7 @@ gnc_split_register_copy_current_internal (SplitRegister* reg,
     }
 
     copied_class = cursor_class;
+    gnc_hook_add_dangler (HOOK_BOOK_CLOSED, clear_copied_item, NULL, NULL);
     LEAVE ("%s %s", use_cut_semantics ? "cut" : "copied",
            cursor_class == CURSOR_CLASS_SPLIT ? "split" : "transaction");
 }



Summary of changes:
 gnucash/register/ledger-core/split-register.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)



More information about the gnucash-changes mailing list