From a5513b45d540b14a5a61198c7f6bdee41e8c2372 Mon Sep 17 00:00:00 2001 From: Richard Cohen Date: Thu, 8 Jun 2023 16:46:53 +0100 Subject: [PATCH] Valgrind: fix "Invalid read" - test-customer ==4028== Invalid read of size 8 ==4028== at 0x4E3F641: gncCustomerGetAddr (gncCustomer.c:579) ==4028== by 0x10A8EE: test_customer (test-customer.c:90) ... ==4028== Address 0x7e861b8 is 168 bytes inside a block of size 272 free'd ==4028== at 0x484620F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==4028== by 0x51526C3: g_type_free_instance (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.7600.1) ==4028== by 0x4E3EDD6: gncCustomerFree (gncCustomer.c:368) ==4028== by 0x4E3F57B: cust_free (gncCustomer.c:551) ==4028== by 0x4E8611E: qof_commit_edit_part2 (qofinstance.cpp:1034) ==4028== by 0x4E3F5D5: gncCustomerCommitEdit (gncCustomer.c:557) ==4028== by 0x4E3EC89: gncCustomerDestroy (gncCustomer.c:338) ==4028== by 0x10A7EC: test_customer (test-customer.c:71) ... ==4028== Block was alloc'd at ==4028== at 0x4848A13: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==4028== by 0x5033550: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==4028== by 0x5157CBC: g_type_create_instance (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.7600.1) ==4028== by 0x513F20F: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.7600.1) ==4028== by 0x51407B7: g_object_new_with_properties (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.7600.1) ==4028== by 0x5141560: g_object_new (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.7600.1) ==4028== by 0x4E3EB0D: gncCustomerCreate (gncCustomer.c:309) ==4028== by 0x10A768: test_customer (test-customer.c:66) ... ==4028== Invalid read of size 8 ==4028== at 0x4E3F796: gncCustomerGetShipAddr (gncCustomer.c:633) ==4028== by 0x10A91D: test_customer (test-customer.c:91) ... ==4028== Address 0x7e86210 is 256 bytes inside a block of size 272 free'd ==4028== at 0x484620F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==4028== by 0x51526C3: g_type_free_instance (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.7600.1) ==4028== by 0x4E3EDD6: gncCustomerFree (gncCustomer.c:368) ==4028== by 0x4E3F57B: cust_free (gncCustomer.c:551) ==4028== by 0x4E8611E: qof_commit_edit_part2 (qofinstance.cpp:1034) ==4028== by 0x4E3F5D5: gncCustomerCommitEdit (gncCustomer.c:557) ==4028== by 0x4E3EC89: gncCustomerDestroy (gncCustomer.c:338) ==4028== by 0x10A7EC: test_customer (test-customer.c:71) ... ==4028== Block was alloc'd at ==4028== at 0x4848A13: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==4028== by 0x5033550: g_malloc0 (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.7600.1) ==4028== by 0x5157CBC: g_type_create_instance (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.7600.1) ==4028== by 0x513F20F: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.7600.1) ==4028== by 0x51407B7: g_object_new_with_properties (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.7600.1) ==4028== by 0x5141560: g_object_new (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.7600.1) ==4028== by 0x4E3EB0D: gncCustomerCreate (gncCustomer.c:309) ==4028== by 0x10A768: test_customer (test-customer.c:66) ... --- libgnucash/engine/test/test-customer.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libgnucash/engine/test/test-customer.c b/libgnucash/engine/test/test-customer.c index 7856798ef9..fc3cc52eca 100644 --- a/libgnucash/engine/test/test-customer.c +++ b/libgnucash/engine/test/test-customer.c @@ -87,12 +87,13 @@ test_customer (void) test_bool_fcn (book, "Active", gncCustomerSetActive, gncCustomerGetActive); - do_test (gncCustomerGetAddr (customer) != NULL, "Addr"); - do_test (gncCustomerGetShipAddr (customer) != NULL, "ShipAddr"); - guid_replace (&guid); customer = gncCustomerCreate (book); count++; + + do_test (gncCustomerGetAddr (customer) != NULL, "Addr"); + do_test (gncCustomerGetShipAddr (customer) != NULL, "ShipAddr"); + gncCustomerSetGUID (customer, &guid); do_test (guid_equal (&guid, gncCustomerGetGUID (customer)), "guid compare"); }