gkdr / libomemo

Implements OMEMO in C.
MIT License
54 stars 16 forks source link

memory leaks in test_storage #52

Open hades opened 9 months ago

hades commented 9 months ago

When running test_storage with address sanitizer, the following memory leaks are found.

To reproduce:

git clone https://github.com/hades/libomemo.git
cd libomemo
git checkout efcf195c243e95131b49d83209b232b70b1e2f27
mkdir build ; cd build
CC=clang cmake .. -DOMEMO_WITH_ASAN=ON
make
ctest --output-on-failure

Error output:

=================================================================
==15719==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x5597d087900e in __interceptor_malloc (/home/hades/dev/libomemo/build/test_storage+0xab00e) (BuildId: e86628c2deb9b1bb8d6929fed4a609fe2da65e06)
    #1 0x7f4a46648948 in g_malloc /usr/src/glib2.0-2.76.1-1/debian/build/deb/../../../glib/gmem.c:130:13

Direct leak of 10 byte(s) in 2 object(s) allocated from:
    #0 0x5597d087900e in __interceptor_malloc (/home/hades/dev/libomemo/build/test_storage+0xab00e) (BuildId: e86628c2deb9b1bb8d6929fed4a609fe2da65e06)
    #1 0x5597d08b344b in int_to_string /home/hades/dev/libomemo/test/../src/libomemo.c:111:16
    #2 0x5597d08b6fba in omemo_devicelist_add /home/hades/dev/libomemo/test/../src/libomemo.c:795:23
    #3 0x5597d08bd428 in omemo_storage_user_devicelist_retrieve /home/hades/dev/libomemo/test/../src/libomemo_storage.c:214:15
    #4 0x5597d08beafc in test_devicelist_retrieve /home/hades/dev/libomemo/test/test_storage.c:82:3
    #5 0x7f4a4687daab in cmocka_run_one_test_or_fixture obj-x86_64-linux-gnu/src/./src/cmocka.c:2801:13

Direct leak of 5 byte(s) in 1 object(s) allocated from:
    #0 0x5597d087900e in __interceptor_malloc (/home/hades/dev/libomemo/build/test_storage+0xab00e) (BuildId: e86628c2deb9b1bb8d6929fed4a609fe2da65e06)
    #1 0x5597d08b344b in int_to_string /home/hades/dev/libomemo/test/../src/libomemo.c:111:16
    #2 0x5597d08b6fba in omemo_devicelist_add /home/hades/dev/libomemo/test/../src/libomemo.c:795:23
    #3 0x5597d08bd428 in omemo_storage_user_devicelist_retrieve /home/hades/dev/libomemo/test/../src/libomemo_storage.c:214:15
    #4 0x5597d08be904 in test_devicelist_retrieve /home/hades/dev/libomemo/test/test_storage.c:74:3
    #5 0x7f4a4687daab in cmocka_run_one_test_or_fixture obj-x86_64-linux-gnu/src/./src/cmocka.c:2801:13

Indirect leak of 144 byte(s) in 6 object(s) allocated from:
    #0 0x5597d087900e in __interceptor_malloc (/home/hades/dev/libomemo/build/test_storage+0xab00e) (BuildId: e86628c2deb9b1bb8d6929fed4a609fe2da65e06)
    #1 0x7f4a46648948 in g_malloc /usr/src/glib2.0-2.76.1-1/debian/build/deb/../../../glib/gmem.c:130:13

Indirect leak of 8 byte(s) in 2 object(s) allocated from:
    #0 0x5597d087900e in __interceptor_malloc (/home/hades/dev/libomemo/build/test_storage+0xab00e) (BuildId: e86628c2deb9b1bb8d6929fed4a609fe2da65e06)
    #1 0x5597d08b7c69 in omemo_devicelist_get_id_list /home/hades/dev/libomemo/test/../src/libomemo.c:940:13
    #2 0x5597d08bec39 in test_devicelist_retrieve /home/hades/dev/libomemo/test/test_storage.c:85:3
    #3 0x7f4a4687daab in cmocka_run_one_test_or_fixture obj-x86_64-linux-gnu/src/./src/cmocka.c:2801:13

Indirect leak of 8 byte(s) in 2 object(s) allocated from:
    #0 0x5597d087900e in __interceptor_malloc (/home/hades/dev/libomemo/build/test_storage+0xab00e) (BuildId: e86628c2deb9b1bb8d6929fed4a609fe2da65e06)
    #1 0x5597d08b7c69 in omemo_devicelist_get_id_list /home/hades/dev/libomemo/test/../src/libomemo.c:940:13
    #2 0x5597d08bece8 in test_devicelist_retrieve /home/hades/dev/libomemo/test/test_storage.c:86:3
    #3 0x7f4a4687daab in cmocka_run_one_test_or_fixture obj-x86_64-linux-gnu/src/./src/cmocka.c:2801:13

Indirect leak of 8 byte(s) in 2 object(s) allocated from:
    #0 0x5597d087900e in __interceptor_malloc (/home/hades/dev/libomemo/build/test_storage+0xab00e) (BuildId: e86628c2deb9b1bb8d6929fed4a609fe2da65e06)
    #1 0x5597d08b7c69 in omemo_devicelist_get_id_list /home/hades/dev/libomemo/test/../src/libomemo.c:940:13
    #2 0x5597d08beb8a in test_devicelist_retrieve /home/hades/dev/libomemo/test/test_storage.c:84:3
    #3 0x7f4a4687daab in cmocka_run_one_test_or_fixture obj-x86_64-linux-gnu/src/./src/cmocka.c:2801:13

Indirect leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x5597d087900e in __interceptor_malloc (/home/hades/dev/libomemo/build/test_storage+0xab00e) (BuildId: e86628c2deb9b1bb8d6929fed4a609fe2da65e06)
    #1 0x5597d08b7c69 in omemo_devicelist_get_id_list /home/hades/dev/libomemo/test/../src/libomemo.c:940:13
    #2 0x5597d08bea41 in test_devicelist_retrieve /home/hades/dev/libomemo/test/test_storage.c:78:3
    #3 0x7f4a4687daab in cmocka_run_one_test_or_fixture obj-x86_64-linux-gnu/src/./src/cmocka.c:2801:13

Indirect leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x5597d087900e in __interceptor_malloc (/home/hades/dev/libomemo/build/test_storage+0xab00e) (BuildId: e86628c2deb9b1bb8d6929fed4a609fe2da65e06)
    #1 0x5597d08b7c69 in omemo_devicelist_get_id_list /home/hades/dev/libomemo/test/../src/libomemo.c:940:13
    #2 0x5597d08be992 in test_devicelist_retrieve /home/hades/dev/libomemo/test/test_storage.c:77:3
    #3 0x7f4a4687daab in cmocka_run_one_test_or_fixture obj-x86_64-linux-gnu/src/./src/cmocka.c:2801:13

SUMMARY: AddressSanitizer: 239 byte(s) leaked in 19 allocation(s).
Neustradamus commented 6 months ago

@gkdr: Have you seen this issue?

There is a PR to solve it!