amazon-ion / ion-c

A C implementation of Amazon Ion.
https://amazon-ion.github.io/ion-docs/
Apache License 2.0
166 stars 43 forks source link

Leak sanitizer reports leak at every ion_reader_open_buffer/ion_reader_close #350

Open Lev275568 opened 1 month ago

Lev275568 commented 1 month ago

Inside function _ion_symbol_table_local_make_system_symbol_table_helper


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

Direct leak of 65536 byte(s) in 1 object(s) allocated from:
    #0 0x610027c09aff in malloc /compiler-rt/lib/asan/asan_malloc_linux.cpp:68:3
    #1 0x610027e1c731 in _ion_alloc_block /src/ionc/ion_allocation.c:182:41
    #2 0x610027e1cb11 in _ion_alloc_with_owner_helper /src/ionc/ion_allocation.c:141:18
    #3 0x610027e1cf2c in _ion_alloc_with_owner /src/ionc/ion_allocation.c:60:11
    #4 0x610027e57722 in _ion_index_grow_array /src/ionc/ion_index.c:275:17
    #5 0x610027e5725d in _ion_index_make_room /src/ionc/ion_index.c:113:5
    #6 0x610027e56af6 in _ion_index_initialize /src/ionc/ion_index.c:76:9
    #7 0x610027e5f8af in _ion_symbol_table_initialize_indices_helper /src/ionc/ion_symbol_table.c:2105:5
    #8 0x610027e5c533 in _ion_symbol_table_lock_helper /src/ionc/ion_symbol_table.c:830:9
    #9 0x610027e5b95a in _ion_symbol_table_local_make_system_symbol_table_helper /src/ionc/ion_symbol_table.c:335:5
    #10 0x610027e596fc in _ion_symbol_table_get_system_symbol_helper /src/ionc/ion_symbol_table.c:269:9
    #11 0x610027e1d886 in _ion_reader_initialize /src/ionc/ion_reader.c:460:5
    #12 0x610027e1d418 in _ion_reader_open_buffer_helper /src/ionc/ion_reader.c:60:5
    #13 0x610027e1d10f in ion_reader_open_buffer /src/ionc/ion_reader.c:32:5
    #14 0x610027c49f7f in threadFunction(void*) test/main.cpp:156:5
    #15 0x610027c05d66 in asan_thread_start(void*) /compiler-rt/lib/asan/asan_interceptors.cpp:239:28

SUMMARY: AddressSanitizer: 65536 byte(s) leaked in 1 allocation(s).

version: ion-c-1.1.3.tar.gz

#include <assert.h>
#include <ionc/ion.h>
#include <pthread.h>
#include <stdio.h>

void* threadFunction(void*)
{
    const char* inputData = "123";
    hREADER hreader;
    assert(IERR_OK == ion_reader_open_buffer(&hreader, (BYTE*)inputData, strlen(inputData), 0));
    assert(IERR_OK == ion_reader_close(hreader));
    return 0;
}

int main()
{
    pthread_attr_t attr;
    assert(pthread_attr_init(&attr) == 0);
    pthread_t ti;
    assert(pthread_create(&ti, &attr, &threadFunction, nullptr) == 0);
    void* retval;
    assert(pthread_join(ti, &retval) == 0);

    return 0;
}
nirosys commented 3 weeks ago

Hello Lev275568, sorry for the delay. I'll take a look at this asap, thank you for the report!

nirosys commented 2 weeks ago

@Lev275568, could you give me some more information about how you've produced this error? What was the compiler, version, OS, build flags, etc.? I haven't been able to reproduce the leak.

Lev275568 commented 2 weeks ago

example.zip Ubuntu 24.04.1 LTS gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0 x86_64

nirosys commented 2 weeks ago

This is perfect. Thank you! Your build script produces it just fine, while I cannot get our cmake build to have the same behavior, interesting. Appears to be related to the threading though. I'll dig more and keep the issue updated.

Thank you again!