From 2f0c04518791de3b3553f259a1138e83b7d77380 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Fri, 7 Jul 2023 15:03:38 +0100 Subject: [PATCH] Valgrind: fix "definitely lost" memory from get_random_string() - test-customer ==88327== 8 bytes in 1 blocks are definitely lost in loss record 13 of 667 ==88327== at 0x4848A13: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==88327== by 0x503C550: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==88327== by 0x10B890: get_random_string_without (test-stuff.c:312) ==88327== by 0x10B90D: get_random_string (test-stuff.c:333) ==88327== by 0x10AC7A: test_string_fcn (test-customer.c:146) ==88327== by 0x10A82E: test_customer (test-customer.c:79) ==88327== by 0x10B012: main (test-customer.c:229) + 3 more --- libgnucash/engine/test/test-customer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libgnucash/engine/test/test-customer.c b/libgnucash/engine/test/test-customer.c index fc3cc52eca..b3f5bac789 100644 --- a/libgnucash/engine/test/test-customer.c +++ b/libgnucash/engine/test/test-customer.c @@ -111,16 +111,16 @@ test_customer (void) g_list_free (list); } { - const char *str = get_random_string(); - const char *res; + char *str = get_random_string(); - res = NULL; gncCustomerBeginEdit(customer); gncCustomerSetName (customer, str); gncCustomerCommitEdit(customer); - res = qof_object_printable (GNC_ID_CUSTOMER, customer); + + const char *res = qof_object_printable (GNC_ID_CUSTOMER, customer); do_test (res != NULL, "Printable NULL?"); do_test (g_strcmp0 (str, res) == 0, "Printable equals"); + g_free (str); } do_test (gncCustomerGetJoblist (customer, TRUE) == NULL, "joblist empty"); @@ -143,7 +143,7 @@ test_string_fcn (QofBook *book, const char *message, const char * (*get)(const GncCustomer *)) { GncCustomer *customer = gncCustomerCreate (book); - char const *str = get_random_string (); + char *str = get_random_string (); do_test (!gncCustomerIsDirty (customer), "test if start dirty"); gncCustomerBeginEdit (customer); @@ -158,6 +158,7 @@ test_string_fcn (QofBook *book, const char *message, */ // do_test (!gncCustomerIsDirty (customer), "test dirty after commit"); do_test (g_strcmp0 (get (customer), str) == 0, message); + g_free (str); gncCustomerSetActive (customer, FALSE); count++; }