From 663dfadb90f3f0c8431c4f8926bd83721d1472e7 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Wed, 28 Jun 2023 08:16:20 +0100 Subject: [PATCH] Fix memory leaks logging with gnc_numeric_to_string() The value returned by gnc_numeric_to_string() needs to be freed. Use gnc_num_dbg_to_string() instead. --- gnucash/gnome/dialog-sx-editor.c | 6 +++--- libgnucash/app-utils/gnc-sx-instance-model.c | 6 +++--- libgnucash/engine/Split.c | 9 ++++++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/gnucash/gnome/dialog-sx-editor.c b/gnucash/gnome/dialog-sx-editor.c index f37ad1c3cf..ec63d3e448 100644 --- a/gnucash/gnome/dialog-sx-editor.c +++ b/gnucash/gnome/dialog-sx-editor.c @@ -474,9 +474,9 @@ check_credit_debit_balance (gpointer key, gpointer val, gpointer ud) *unbalanced |= !(gnc_numeric_zero_p (diff)); DEBUG ("%p | %s [%s - %s = %s]", key, result, - gnc_numeric_to_string (tcds->debitSum), - gnc_numeric_to_string (tcds->creditSum), - gnc_numeric_to_string (diff)); + gnc_num_dbg_to_string (tcds->debitSum), + gnc_num_dbg_to_string (tcds->creditSum), + gnc_num_dbg_to_string (diff)); } static gboolean diff --git a/libgnucash/app-utils/gnc-sx-instance-model.c b/libgnucash/app-utils/gnc-sx-instance-model.c index d23659c538..0959cf99aa 100644 --- a/libgnucash/app-utils/gnc-sx-instance-model.c +++ b/libgnucash/app-utils/gnc-sx-instance-model.c @@ -1141,7 +1141,7 @@ split_apply_exchange_rate (Split *split, GHashTable *bindings, if (exchange_rate_var != NULL) { exchange_rate = exchange_rate_var->value; - DEBUG("exchange_rate is %s", gnc_numeric_to_string (exchange_rate)); + DEBUG("exchange_rate is %s", gnc_num_dbg_to_string (exchange_rate)); } g_free (exchange_rate_var_name); @@ -1154,7 +1154,7 @@ split_apply_exchange_rate (Split *split, GHashTable *bindings, GNC_HOW_RND_ROUND_HALF_UP); - DEBUG("amount is %s for memo split '%s'", gnc_numeric_to_string (amt), + DEBUG("amount is %s for memo split '%s'", gnc_num_dbg_to_string (amt), xaccSplitGetMemo (split)); xaccSplitSetAmount(split, amt); /* marks split dirty */ @@ -1318,7 +1318,7 @@ create_each_transaction_helper(Transaction *template_txn, void *user_data) creation_data); xaccSplitSetValue(copying_split, final); DEBUG("value is %s for memo split '%s'", - gnc_numeric_to_string (final), + gnc_num_dbg_to_string (final), xaccSplitGetMemo (copying_split)); if (! gnc_commodity_equal(split_cmdty, txn_cmdty)) { diff --git a/libgnucash/engine/Split.c b/libgnucash/engine/Split.c index 9efe633c94..252babe507 100644 --- a/libgnucash/engine/Split.c +++ b/libgnucash/engine/Split.c @@ -1271,8 +1271,15 @@ xaccSplitSetValue (Split *s, gnc_numeric amt) GNC_HOW_RND_ROUND_HALF_UP); if (gnc_numeric_check(new_val) == GNC_ERROR_OK && !(gnc_numeric_zero_p (new_val) && !gnc_numeric_zero_p (amt))) + { s->value = new_val; - else PERR("numeric error %s in converting the split value's denominator with amount %s and denom %d", gnc_numeric_errorCode_to_string(gnc_numeric_check(new_val)), gnc_numeric_to_string(amt), get_currency_denom(s)); + } + else + { + PERR("numeric error %s in converting the split value's denominator with amount %s and denom %d", + gnc_numeric_errorCode_to_string(gnc_numeric_check(new_val)), + gnc_num_dbg_to_string (amt), get_currency_denom(s)); + } SET_GAINS_VDIRTY(s); mark_split (s);