From 47f76fcf0332695c03ef103f284112e94801c1a6 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Fri, 7 Jul 2023 17:47:04 +0100 Subject: [PATCH 1/6] Valgrind: fix "definitely lost" memory from get_random_string() - test-address ==88262== 6 bytes in 1 blocks are definitely lost in loss record 5 of 2,117 ==88262== at 0x4848A13: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==88262== by 0x503C550: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==88262== by 0x10B043: get_random_string_without (test-stuff.c:312) ==88262== by 0x10B0C0: get_random_string (test-stuff.c:333) ==88262== by 0x10A6E0: test_string_fcn (test-address.c:79) ==88262== by 0x10A694: test_address (test-address.c:69) ==88262== by 0x10A7C5: main (test-address.c:94) + 7 more --- libgnucash/engine/test/test-address.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libgnucash/engine/test/test-address.c b/libgnucash/engine/test/test-address.c index 334da191d6..df620a8169 100644 --- a/libgnucash/engine/test/test-address.c +++ b/libgnucash/engine/test/test-address.c @@ -76,12 +76,13 @@ test_string_fcn (GncAddress *address, const char *message, void (*set) (GncAddress *, const char *str), const char * (*get)(const GncAddress *)) { - char const *str = get_random_string (); + char *str = get_random_string (); do_test (!gncAddressIsDirty (address), "test if start dirty"); set (address, str); do_test (gncAddressIsDirty (address), "test dirty later"); do_test (g_strcmp0 (get (address), str) == 0, message); + g_free (str); gncAddressClearDirty (address); } From 394823a7345f40543c3b506c657570e9e08f6a3a Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Fri, 7 Jul 2023 17:47:15 +0100 Subject: [PATCH 2/6] Valgrind: fix "definitely lost" memory from get_random_string() - test-commodities ==88718== 8 bytes in 1 blocks are definitely lost in loss record 21 of 1,880 ==88718== at 0x4848A13: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==88718== by 0x503C550: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==88718== by 0x11D6B9: get_random_string_without (test-stuff.c:312) ==88718== by 0x11D736: get_random_string (test-stuff.c:333) ==88718== by 0x116A91: test_commodity() (test-commodities.cpp:60) ==88718== by 0x117355: main (test-commodities.cpp:196) + 5 more --- libgnucash/engine/test/test-commodities.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libgnucash/engine/test/test-commodities.cpp b/libgnucash/engine/test/test-commodities.cpp index 089880f9dc..7ed5871678 100644 --- a/libgnucash/engine/test/test-commodities.cpp +++ b/libgnucash/engine/test/test-commodities.cpp @@ -72,6 +72,7 @@ test_commodity(void) do_test( g_strcmp0(fullname, gnc_commodity_get_fullname(com)) == 0, "fullnames equal test"); + g_free (fullname); do_test( g_strcmp0(name_space, gnc_commodity_get_namespace(com)) == 0, @@ -80,10 +81,12 @@ test_commodity(void) do_test( g_strcmp0(mnemonic, gnc_commodity_get_mnemonic(com)) == 0, "mnemonic equal test"); + g_free (mnemonic); do_test( g_strcmp0(cusip, gnc_commodity_get_cusip(com)) == 0, "cusip equal test"); + g_free (cusip); do_test( gnc_commodity_get_fraction(com) == fraction, @@ -126,6 +129,10 @@ test_commodity(void) com2 = gnc_commodity_new(book, fullname, name_space, mnemonic, cusip, fraction); + g_free (fullname); + g_free (mnemonic); + g_free (cusip); + do_test( gnc_commodity_equiv(com, com2), "commodity equiv"); From 2f0c04518791de3b3553f259a1138e83b7d77380 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Fri, 7 Jul 2023 15:03:38 +0100 Subject: [PATCH 3/6] 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++; } From 49240e9b5acfbe873406b39ce46b5cdb49c79173 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Fri, 7 Jul 2023 16:46:19 +0100 Subject: [PATCH 4/6] 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++; } From 30b47d16691df008440949d1d7c73db6154c1afb Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Fri, 7 Jul 2023 18:21:31 +0100 Subject: [PATCH 5/6] Valgrind: fix "definitely lost" memory from get_random_string() - test-job ==88779== 8 bytes in 1 blocks are definitely lost in loss record 9 of 461 ==88779== at 0x4848A13: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==88779== by 0x503C550: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==88779== by 0x10B871: get_random_string_without (test-stuff.c:312) ==88779== by 0x10B8EE: get_random_string (test-stuff.c:333) ==88779== by 0x10AB9F: test_string_fcn (test-job.c:157) ==88779== by 0x10A7B1: test_job (test-job.c:87) ==88779== by 0x10AFF3: main (test-job.c:262) + 3 more --- libgnucash/engine/test/test-job.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libgnucash/engine/test/test-job.c b/libgnucash/engine/test/test-job.c index 2b5b4f8155..737f168017 100644 --- a/libgnucash/engine/test/test-job.c +++ b/libgnucash/engine/test/test-job.c @@ -113,13 +113,13 @@ test_job (void) } #endif { - const char *str = get_random_string(); - const char *res; + char *str = get_random_string(); gncJobSetName (job, str); - res = qof_object_printable (GNC_ID_JOB, job); + const char *res = qof_object_printable (GNC_ID_JOB, job); do_test (res != NULL, "Printable NULL?"); do_test (g_strcmp0 (str, res) == 0, "Printable equals"); + g_free (str); } { GList *list; @@ -154,7 +154,7 @@ test_string_fcn (QofBook *book, const char *message, const char * (*get)(const GncJob *)) { GncJob *job = gncJobCreate (book); - char const *str = get_random_string (); + char *str = get_random_string (); do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test if start dirty"); gncJobBeginEdit (job); @@ -169,6 +169,7 @@ test_string_fcn (QofBook *book, const char *message, */ // do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty after commit"); do_test (g_strcmp0 (get (job), str) == 0, message); + g_free (str); gncJobSetActive (job, FALSE); count++; } From a36844720d796a4dff681fbc33a4ccc5667b1abd Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Fri, 7 Jul 2023 15:06:52 +0100 Subject: [PATCH 6/6] 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++; }