From e43982375c7b0904636f286064ead2e5330f01e0 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Thu, 6 Jul 2023 17:27:03 +0100 Subject: [PATCH 1/8] Valgrind: fix "definitely lost" memory in test - sqlite3test ==64824== 171 (88 direct, 83 indirect) bytes in 1 blocks are definitely lost in loss record 392 of 418 ==64824== at 0x4843FA3: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==64824== by 0x528A935: qof_session_new (qofsession.cpp:148) ==64824== by 0x141832: main (sqlite3test.c:34) --- bindings/python/sqlite3test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bindings/python/sqlite3test.c b/bindings/python/sqlite3test.c index b8c41889f4..9195bcd97d 100644 --- a/bindings/python/sqlite3test.c +++ b/bindings/python/sqlite3test.c @@ -36,6 +36,7 @@ int main() qof_session_load(s, NULL); qof_session_save(s, NULL); qof_session_end(s); + qof_session_destroy(s); unlink(TESTFILE); return 0; } From 4c48134d91afd98586f3e5c081291be41af3b147 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Thu, 6 Jul 2023 18:51:39 +0100 Subject: [PATCH 2/8] Valgrind: fix "definitely lost" memory in test - test-import-backend ==66703== 24 bytes in 1 blocks are definitely lost in loss record 116 of 284 ==66703== at 0x4843828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==66703== by 0x4A79948: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==66703== by 0x4A6D909: g_list_prepend (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==66703== by 0x31EB41: ImportBackendTest::SetUp() (gtest-import-backend.cpp:145) --- gnucash/import-export/test/gtest-import-backend.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/gnucash/import-export/test/gtest-import-backend.cpp b/gnucash/import-export/test/gtest-import-backend.cpp index 8fc035ba64..3cdfbdd9f6 100644 --- a/gnucash/import-export/test/gtest-import-backend.cpp +++ b/gnucash/import-export/test/gtest-import-backend.cpp @@ -156,6 +156,7 @@ protected: m_import_acc->free(); m_dest_acc->free(); m_trans->free(); + g_list_free (m_splitList); m_split->free(); } From f1e889dbcb4aa91e11dd56706959b0ea1580e2e4 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Mon, 17 Jul 2023 19:18:27 +0100 Subject: [PATCH 3/8] 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); From 69df6ea57d14ec6cb761b74931a343a14ce66a79 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Wed, 5 Jul 2023 15:43:27 +0100 Subject: [PATCH 4/8] Valgrind: fix "definitely lost" memory in test - test-qofquerycore ==87254== 40 (24 direct, 16 indirect) bytes in 1 blocks are definitely lost in loss record 107 of 242 ==87254== at 0x4843828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==87254== by 0x503B948: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==87254== by 0x502F909: g_list_prepend (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==87254== by 0x194E83: QofQueryCoreTest_construct_predicate_guid_Test::TestBody() (gtest-qofquerycore.cpp:94) --- libgnucash/engine/test/gtest-qofquerycore.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libgnucash/engine/test/gtest-qofquerycore.cpp b/libgnucash/engine/test/gtest-qofquerycore.cpp index 2a5d340e8a..d428b9725a 100644 --- a/libgnucash/engine/test/gtest-qofquerycore.cpp +++ b/libgnucash/engine/test/gtest-qofquerycore.cpp @@ -102,6 +102,7 @@ TEST_F(QofQueryCoreTest, construct_predicate_guid) EXPECT_TRUE (guid_equal (guid, (const GncGUID*)pdata->guids->data)); EXPECT_EQ (NULL, pdata->guids->next); qof_query_core_predicate_free ((QofQueryPredData*) pdata); + g_list_free_full (guidlist, (GDestroyNotify)guid_free); } TEST_F(QofQueryCoreTest, construct_predicate_int32) From 378dc405859adf58875accd325b026e6a3c3529e Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Wed, 5 Jul 2023 16:42:45 +0100 Subject: [PATCH 5/8] Valgrind: fix "definitely lost" memory in test - test-resolve-file-path ==91379== 19 bytes in 1 blocks are definitely lost in loss record 2 of 9 ==91379== at 0x4843828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==91379== by 0x48D1948: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==91379== by 0x48ED5B0: g_strconcat (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==91379== by 0x48B845F: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==91379== by 0x48B869E: g_dir_make_tmp (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==91379== by 0x10935E: main (test-resolve-file-path.c:71) --- libgnucash/core-utils/test/test-resolve-file-path.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libgnucash/core-utils/test/test-resolve-file-path.c b/libgnucash/core-utils/test/test-resolve-file-path.c index 7424af2544..66a8cce3e6 100644 --- a/libgnucash/core-utils/test/test-resolve-file-path.c +++ b/libgnucash/core-utils/test/test-resolve-file-path.c @@ -65,7 +65,7 @@ main(int argc, char **argv) * used to pass invalid home directories manually. The * test error messages should then show the system's temporary * directory to be used instead */ - home_dir = argv[1]; + home_dir = g_strdup (argv[1]); else /* Set up a fake home directory to play with */ home_dir = g_dir_make_tmp("gnucashXXXXXX", NULL); @@ -105,6 +105,7 @@ main(int argc, char **argv) g_free(daout); } + g_free (home_dir); print_test_results(); return get_rv(); } From b7d278556f506715876b9c22f04b7a8243f078e3 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Tue, 18 Jul 2023 16:20:47 +0100 Subject: [PATCH 6/8] Valgrind: fix "definitely lost" memory in test - test-string-converters ==68902== 8 bytes in 1 blocks are definitely lost in loss record 7 of 251 ==68902== at 0x4843828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==68902== by 0x5225948: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==68902== by 0x5240ED2: g_strdup (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==68902== by 0x13135E: g_strdup_inline (gstrfuncs.h:321) ==68902== by 0x13135E: dom_tree_to_text(_xmlNode*) (sixtp-dom-parsers.cpp:500) ==68902== by 0x141758: test_bad_string() (test-string-converters.cpp:70) ==68902== by 0x1417D8: main (test-string-converters.cpp:82) ==68902== ==68902== 93 bytes in 5 blocks are definitely lost in loss record 199 of 251 ==68902== at 0x4843828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==68902== by 0x5225948: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==68902== by 0x5240ED2: g_strdup (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==68902== by 0x13135E: g_strdup_inline (gstrfuncs.h:321) ==68902== by 0x13135E: dom_tree_to_text(_xmlNode*) (sixtp-dom-parsers.cpp:500) ==68902== by 0x14169B: test_string_converters() (test-string-converters.cpp:55) ==68902== by 0x1417D3: main (test-string-converters.cpp:81) ==68902== ==68902== 260 (120 direct, 140 indirect) bytes in 1 blocks are definitely lost in loss record 242 of 251 ==68902== at 0x4843828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==68902== by 0x48D5B84: xmlNewNode (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.14) ==68902== by 0x133873: text_to_dom_tree(char const*, char const*) (sixtp-dom-generators.cpp:53) ==68902== by 0x141748: test_bad_string() (test-string-converters.cpp:68) ==68902== by 0x1417D8: main (test-string-converters.cpp:82) ==68902== ==68902== 1,353 (600 direct, 753 indirect) bytes in 5 blocks are definitely lost in loss record 248 of 251 ==68902== at 0x4843828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==68902== by 0x48D5B84: xmlNewNode (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.14) ==68902== by 0x133873: text_to_dom_tree(char const*, char const*) (sixtp-dom-generators.cpp:53) ==68902== by 0x14168B: test_string_converters() (test-string-converters.cpp:54) ==68902== by 0x1417D3: main (test-string-converters.cpp:81) ==68902== --- libgnucash/backend/xml/test/test-string-converters.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libgnucash/backend/xml/test/test-string-converters.cpp b/libgnucash/backend/xml/test/test-string-converters.cpp index 22509aad04..c2baf05738 100644 --- a/libgnucash/backend/xml/test/test-string-converters.cpp +++ b/libgnucash/backend/xml/test/test-string-converters.cpp @@ -57,6 +57,9 @@ test_string_converters (void) do_test_args ( g_strcmp0 (backout, mark) == 0, "string converting", __FILE__, __LINE__, "with string %s", mark); + + g_free (backout); + xmlFreeNode (test_node); } } @@ -71,6 +74,9 @@ test_bad_string (void) do_test_args (g_strcmp0 (backout, sanitized) == 0, "string sanitizing", __FILE__, __LINE__, "with string %s", badstr); + + g_free (backout); + xmlFreeNode (test_node); } int From d808fddc956909a27be08d728e6c2cfc8daa5253 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Thu, 6 Jul 2023 16:11:29 +0100 Subject: [PATCH 7/8] Valgrind: fix "definitely lost" memory in test - test-userdata-dir-invalid-home ==66427== 128 bytes in 1 blocks are definitely lost in loss record 22 of 25 ==66427== at 0x4843738: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==66427== by 0x49B85EF: g_realloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==66427== by 0x49D6EF1: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==66427== by 0x49D6F6F: g_string_sized_new (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==66427== by 0x499AB00: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==66427== by 0x499B2D8: g_build_filename (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==66427== by 0x10A498: main (test-userdata-dir-invalid-home.c:74) ==66427== --- libgnucash/core-utils/test/test-userdata-dir-invalid-home.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libgnucash/core-utils/test/test-userdata-dir-invalid-home.c b/libgnucash/core-utils/test/test-userdata-dir-invalid-home.c index b81d521333..3ec1e98946 100644 --- a/libgnucash/core-utils/test/test-userdata-dir-invalid-home.c +++ b/libgnucash/core-utils/test/test-userdata-dir-invalid-home.c @@ -83,6 +83,8 @@ main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) * The code should fall back to using the temporary * directory in that case. */ g_setenv("HOME", homedir, TRUE); + g_free (homedir); + for (i = 0; strs2[i].funcname != NULL; i++) { char *daout; From 264091190144f44549673e5ab9dd617950b6b3c0 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Wed, 5 Jul 2023 14:57:34 +0100 Subject: [PATCH 8/8] Valgrind: fix "definitely lost/still reachable" memory in test - test-xml2-is-file Valgrind uses "still reachable" because of the call to exit() ==87185== 94 bytes in 1 blocks are still reachable in loss record 193 of 241 ==87185== at 0x4843828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==87185== by 0x15C234: main (test-xml2-is-file.cpp:42) ==87185== --- libgnucash/backend/xml/test/test-xml2-is-file.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libgnucash/backend/xml/test/test-xml2-is-file.cpp b/libgnucash/backend/xml/test/test-xml2-is-file.cpp index 717bb5e5b4..8e1cf27c02 100644 --- a/libgnucash/backend/xml/test/test-xml2-is-file.cpp +++ b/libgnucash/backend/xml/test/test-xml2-is-file.cpp @@ -19,7 +19,8 @@ \********************************************************************/ #include #include -#include + +#include #include "test-engine-stuff.h" #include "io-gncxml-v2.h" @@ -38,11 +39,9 @@ main (int argc, char** argv) directory = "test-files/xml2"; } - auto size{strlen (directory) + 1 + strlen (FILENAME) + 1}; - char* filename = static_cast (malloc (size)); - snprintf (filename, size, "%s/%s", directory, FILENAME); - do_test (gnc_is_xml_data_file_v2 (filename, NULL), "gnc_is_xml_data_file_v2"); + auto filename = std::string{directory} + '/' + FILENAME; + do_test (gnc_is_xml_data_file_v2 (filename.c_str(), NULL), "gnc_is_xml_data_file_v2"); print_test_results (); - exit (get_rv ()); + return get_rv (); }