From 49240e9b5acfbe873406b39ce46b5cdb49c79173 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Fri, 7 Jul 2023 16:46:19 +0100 Subject: [PATCH] Valgrind: fix "definitely lost" memory from get_random_string() - test-employee ==88366== 8 bytes in 1 blocks are definitely lost in loss record 11 of 474 ==88366== at 0x4848A13: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==88366== by 0x503C550: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==88366== by 0x10B7E9: get_random_string_without (test-stuff.c:312) ==88366== by 0x10B866: get_random_string (test-stuff.c:333) ==88366== by 0x10AB64: test_string_fcn (test-employee.c:140) ==88366== by 0x10A7C1: test_employee (test-employee.c:87) ==88366== by 0x10AF6B: main (test-employee.c:246) + 4 more --- libgnucash/engine/test/test-employee.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libgnucash/engine/test/test-employee.c b/libgnucash/engine/test/test-employee.c index 1010febf36..cfefd2e214 100644 --- a/libgnucash/engine/test/test-employee.c +++ b/libgnucash/engine/test/test-employee.c @@ -117,15 +117,14 @@ test_employee (void) g_list_free (list); } { - const char *str = get_random_string(); - const char *res; - GncAddress *addr; + char *str = get_random_string(); - addr = gncEmployeeGetAddr (employee); + GncAddress *addr = gncEmployeeGetAddr (employee); gncAddressSetName (addr, str); - res = qof_object_printable (GNC_ID_EMPLOYEE, employee); + const char *res = qof_object_printable (GNC_ID_EMPLOYEE, employee); do_test (res != NULL, "Printable NULL?"); do_test (g_strcmp0 (str, res) == 0, "Printable equals"); + g_free (str); } qof_book_destroy (book); @@ -137,7 +136,7 @@ test_string_fcn (QofBook *book, const char *message, const char * (*get)(const GncEmployee *)) { GncEmployee *employee = gncEmployeeCreate (book); - char const *str = get_random_string (); + char *str = get_random_string (); do_test (!gncEmployeeIsDirty (employee), "test if start dirty"); gncEmployeeBeginEdit (employee); @@ -152,6 +151,7 @@ test_string_fcn (QofBook *book, const char *message, */ // do_test (!gncEmployeeIsDirty (employee), "test dirty after commit"); do_test (g_strcmp0 (get (employee), str) == 0, message); + g_free (str); gncEmployeeSetActive (employee, FALSE); count++; }