From f1e889dbcb4aa91e11dd56706959b0ea1580e2e4 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Mon, 17 Jul 2023 19:18:27 +0100 Subject: [PATCH] Valgrind: fix "definitely lost" memory in test - test-lots ==67054== 320 bytes in 32 blocks are definitely lost in loss record 2,213 of 2,238 ==67054== at 0x4848A13: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==67054== by 0x503C550: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==67054== by 0x118AD8: get_random_transaction_with_currency (test-engine-stuff.cpp:1395) ==67054== by 0x119897: add_random_transactions_to_book (test-engine-stuff.cpp:1848) ==67054== by 0x115FE8: run_test() (test-lots.cpp:99) ==67054== by 0x1160BF: main (test-lots.cpp:135) ==67054== --- libgnucash/engine/test-core/test-engine-stuff.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libgnucash/engine/test-core/test-engine-stuff.cpp b/libgnucash/engine/test-core/test-engine-stuff.cpp index 8e93239e75..c1a1960f3f 100644 --- a/libgnucash/engine/test-core/test-engine-stuff.cpp +++ b/libgnucash/engine/test-core/test-engine-stuff.cpp @@ -52,6 +52,9 @@ #include #include #include + +#include + #include #include "Account.h" @@ -1376,8 +1379,6 @@ get_random_transaction_with_currency(QofBook *book, { Transaction* trans; KvpFrame *f; - gint num; - gchar *numstr; if (!account_list) { @@ -1392,8 +1393,6 @@ get_random_transaction_with_currency(QofBook *book, return NULL; } - numstr = g_new0(gchar, 10); - trans = xaccMallocTransaction(book); xaccTransBeginEdit(trans); @@ -1402,9 +1401,10 @@ get_random_transaction_with_currency(QofBook *book, currency ? currency : get_random_commodity (book)); - num = get_random_int_in_range (1, max_trans_num); - g_snprintf(numstr, 10, "%d", num); - xaccTransSetNum(trans, numstr); + gint num = get_random_int_in_range (1, max_trans_num); + auto numstr = std::to_string(num); + xaccTransSetNum(trans, numstr.c_str()); + set_tran_random_string_from_array(trans, xaccTransSetDescription, sane_descriptions); trn_add_ran_time(trans, xaccTransSetDatePostedSecs);