From a36844720d796a4dff681fbc33a4ccc5667b1abd Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Fri, 7 Jul 2023 15:06:52 +0100 Subject: [PATCH] Valgrind: fix "definitely lost" memory from get_random_string() - test-vendor ==88804== 8 bytes in 1 blocks are definitely lost in loss record 12 of 479 ==88804== at 0x4848A13: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==88804== by 0x503C550: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==88804== by 0x10B5D8: get_random_string_without (test-stuff.c:312) ==88804== by 0x10B655: get_random_string (test-stuff.c:333) ==88804== by 0x10AA92: test_string_fcn (test-vendor.c:138) ==88804== by 0x10A76B: test_vendor (test-vendor.c:88) ==88804== by 0x10AD5A: main (test-vendor.c:246) + 3 more --- libgnucash/engine/test/test-vendor.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libgnucash/engine/test/test-vendor.c b/libgnucash/engine/test/test-vendor.c index 8e3e19cfd7..47bdb057d7 100644 --- a/libgnucash/engine/test/test-vendor.c +++ b/libgnucash/engine/test/test-vendor.c @@ -117,13 +117,13 @@ test_vendor (void) g_list_free (list); } { - const char *str = get_random_string(); - const char *res; + char *str = get_random_string(); gncVendorSetName (vendor, str); - res = qof_object_printable (GNC_ID_VENDOR, vendor); + const char *res = qof_object_printable (GNC_ID_VENDOR, vendor); do_test (res != NULL, "Printable NULL?"); do_test (g_strcmp0 (str, res) == 0, "Printable equals"); + g_free (str); } qof_book_destroy (book); @@ -135,7 +135,7 @@ test_string_fcn (QofBook *book, const char *message, const char * (*get)(const GncVendor *)) { GncVendor *vendor = gncVendorCreate (book); - char const *str = get_random_string (); + char *str = get_random_string (); do_test (!gncVendorIsDirty (vendor), "test if start dirty"); gncVendorBeginEdit (vendor); @@ -150,6 +150,7 @@ test_string_fcn (QofBook *book, const char *message, */ // do_test (!gncVendorIsDirty (vendor), "test dirty after commit"); do_test (g_strcmp0 (get (vendor), str) == 0, message); + g_free (str); gncVendorSetActive (vendor, FALSE); count++; }