kriszyp / lmdb-js

Simple, efficient, ultra-fast, scalable data store wrapper for LMDB
Other
479 stars 39 forks source link

AddressSanitizer: alloc-dealloc-mismatch (operator new [] vs free) #251

Open cxcorp opened 11 months ago

cxcorp commented 11 months ago

When compiling native node dependencies with -fsanitize=address to enable AddressSanitizer, there appears to be warnings originating from lmdb-js.

For example, when using a project that uses parcel's watch mode:

$ CFLAGS="-g -fsanitize=address -fno-omit-frame-pointer" \
CXXFLAGS="-g -fsanitize=address -fno-omit-frame-pointer" \
LDFLAGS="-fsanitize=address" \
npm_config_build_from_source=true \
JOBS=8 \
yarn install

$ LD_PRELOAD="/usr/lib64/libasan.so.8.0.0" yarn frontend:dev:start

Server running at http://localhost:1234
=================================================================
==18439==ERROR: AddressSanitizer: alloc-dealloc-mismatch (operator new [] vs free) on 0x625009830100
    #0 0x7f34fb0d7fc8 in __interceptor_free.part.0 (/usr/lib64/libasan.so.8.0.0+0xd7fc8) (BuildId: dc689b05ca2577037af24700212bb5cce1f91c8a)
    #1 0x7f34eb06866f in WriteWorker::DoWrites(MDB_txn*, EnvWrap*, unsigned int*, WriteWorker*) ../src/writer.cpp:298
    #2 0x7f34eb0696b3 in WriteWorker::Write() ../src/writer.cpp:400
    #3 0x7f34eb069cb3 in do_write(napi_env__*, void*) ../src/writer.cpp:362
    #4 0xb41369 in node::ThreadPoolWork::ScheduleWork()::{lambda(uv_work_s*)#1}::_FUN(uv_work_s*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xb41369) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #5 0x1659c73 in worker ../deps/uv/src/threadpool.c:122
    #6 0x7f34faaae906 in start_thread (/lib64/libc.so.6+0x8c906) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)
    #7 0x7f34fab3486f in __clone3 (/lib64/libc.so.6+0x11286f) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)

0x625009830100 is located 0 bytes inside of 9593-byte region [0x625009830100,0x625009832679)
allocated by thread T10 here:
    #0 0x7f34fb0d9f98 in operator new[](unsigned long) (/usr/lib64/libasan.so.8.0.0+0xd9f98) (BuildId: dc689b05ca2577037af24700212bb5cce1f91c8a)
    #1 0x7f34eb0c6ac3 in Compression::compress(MDB_val*, void (*)(MDB_val&)) ../src/compression.cpp:124
    #2 0x7f34eb0c6ac3 in Compression::compressInstruction(EnvWrap*, double*) ../src/compression.cpp:97
    #3 0x7f34eb0a5e02 in Napi::AsyncWorker::OnExecute(Napi::Env) ../../node-addon-api/napi-inl.h:4895
    #4 0x7f34eb0a5e02 in Napi::AsyncWorker::OnAsyncWorkExecute(napi_env__*, void*) ../../node-addon-api/napi-inl.h:4881
    #5 0xb41369 in node::ThreadPoolWork::ScheduleWork()::{lambda(uv_work_s*)#1}::_FUN(uv_work_s*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xb41369) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #6 0x1659c73 in worker ../deps/uv/src/threadpool.c:122
    #7 0x7f34faaae906 in start_thread (/lib64/libc.so.6+0x8c906) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)

Thread T8 created by T0 here:
    #0 0x7f34fb048966 in pthread_create (/usr/lib64/libasan.so.8.0.0+0x48966) (BuildId: dc689b05ca2577037af24700212bb5cce1f91c8a)
    #1 0x166d2bb in uv_thread_create_ex ../deps/uv/src/unix/thread.c:279
    #2 0x166d2bb in uv_thread_create ../deps/uv/src/unix/thread.c:233
    #3 0x165a04a in init_threads ../deps/uv/src/threadpool.c:230
    #4 0x165a04a in init_once ../deps/uv/src/threadpool.c:257
    #5 0x7f34faab3af2 in __pthread_once_slow (/lib64/libc.so.6+0x91af2) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)
    #6 0x166d628 in uv_once ../deps/uv/src/unix/thread.c:440
    #7 0x165a229 in uv__work_submit ../deps/uv/src/threadpool.c:266
    #8 0x1665321 in uv_fs_stat ../deps/uv/src/unix/fs.c:2128
    #9 0xb90dd4 in node::fs::Stat(v8::FunctionCallbackInfo<v8::Value> const&) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xb90dd4) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #10 0xdbaa7f in v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xdbaa7f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #11 0xdbbfbe in v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xdbbfbe) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #12 0x16fb7f8 in Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x16fb7f8) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #13 0x167f74f in Builtins_InterpreterEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167f74f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #14 0x167f74f in Builtins_InterpreterEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167f74f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #15 0x167f74f in Builtins_InterpreterEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167f74f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #16 0x174a1cd in Builtins_PromiseConstructor (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x174a1cd) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #17 0x167d26b in Builtins_JSBuiltinsConstructStub (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167d26b) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #18 0x179967e in Builtins_ConstructHandler (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x179967e) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #19 0x167f74f in Builtins_InterpreterEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167f74f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #20 0x167f74f in Builtins_InterpreterEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167f74f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #21 0x167f74f in Builtins_InterpreterEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167f74f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #22 0x16b343e in Builtins_AsyncFunctionAwaitResolveClosure (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x16b343e) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #23 0x174bcf0 in Builtins_PromiseFulfillReactionJob (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x174bcf0) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #24 0x16a4bba in Builtins_RunMicrotasks (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x16a4bba) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #25 0x167dc82 in Builtins_JSRunMicrotasksEntry (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167dc82) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #26 0xe9d659 in v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xe9d659) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #27 0xe9e25f in v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [clone .constprop.84] (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xe9e25f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #28 0xe9e969 in v8::internal::Execution::TryRunMicrotasks(v8::internal::Isolate*, v8::internal::MicrotaskQueue*, v8::internal::MaybeHandle<v8::internal::Object>*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xe9e969) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #29 0xecbe69 in v8::internal::MicrotaskQueue::RunMicrotasks(v8::internal::Isolate*) [clone .part.50] (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xecbe69) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #30 0xecc241 in v8::internal::MicrotaskQueue::PerformCheckpoint(v8::Isolate*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xecc241) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #31 0xdbaa7f in v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xdbaa7f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #32 0xdbbfbe in v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xdbbfbe) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #33 0x16fb7f8 in Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x16fb7f8) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #34 0x167f74f in Builtins_InterpreterEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167f74f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #35 0x167dd5b in Builtins_JSEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167dd5b) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #36 0x167da82 in Builtins_JSEntry (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167da82) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #37 0xe9d18d in v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xe9d18d) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #38 0xe9e37e in v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xe9e37e) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #39 0xd786e2 in v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xd786e2) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #40 0xabcd85 in node::InternalCallbackScope::Close() (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xabcd85) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #41 0xabce00 in node::InternalCallbackScope::~InternalCallbackScope() (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xabce00) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #42 0xb35fb8 in node::StartExecution(node::Environment*, std::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xb35fb8) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #43 0xac1316 in node::LoadEnvironment(node::Environment*, std::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xac1316) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #44 0xbc113f in node::NodeMainInstance::Run() (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xbc113f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #45 0xb35bc7 in node::LoadSnapshotDataAndRun(node::SnapshotData const**, node::InitializationResult const*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xb35bc7) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #46 0xb3976e in node::Start(int, char**) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xb3976e) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #47 0x7f34faa49b49 in __libc_start_call_main (/lib64/libc.so.6+0x27b49) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)
    #48 0x7f34faa49c0a in __libc_start_main_alias_2 (/lib64/libc.so.6+0x27c0a) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)
    #49 0xabbded in _start (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xabbded) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)

Thread T10 created by T0 here:
    #0 0x7f34fb048966 in pthread_create (/usr/lib64/libasan.so.8.0.0+0x48966) (BuildId: dc689b05ca2577037af24700212bb5cce1f91c8a)
    #1 0x166d2bb in uv_thread_create_ex ../deps/uv/src/unix/thread.c:279
    #2 0x166d2bb in uv_thread_create ../deps/uv/src/unix/thread.c:233
    #3 0x165a04a in init_threads ../deps/uv/src/threadpool.c:230
    #4 0x165a04a in init_once ../deps/uv/src/threadpool.c:257
    #5 0x7f34faab3af2 in __pthread_once_slow (/lib64/libc.so.6+0x91af2) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)
    #6 0x166d628 in uv_once ../deps/uv/src/unix/thread.c:440
    #7 0x165a229 in uv__work_submit ../deps/uv/src/threadpool.c:266
    #8 0x1665321 in uv_fs_stat ../deps/uv/src/unix/fs.c:2128
    #9 0xb90dd4 in node::fs::Stat(v8::FunctionCallbackInfo<v8::Value> const&) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xb90dd4) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #10 0xdbaa7f in v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xdbaa7f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #11 0xdbbfbe in v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xdbbfbe) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #12 0x16fb7f8 in Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x16fb7f8) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #13 0x167f74f in Builtins_InterpreterEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167f74f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #14 0x167f74f in Builtins_InterpreterEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167f74f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #15 0x167f74f in Builtins_InterpreterEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167f74f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #16 0x174a1cd in Builtins_PromiseConstructor (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x174a1cd) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #17 0x167d26b in Builtins_JSBuiltinsConstructStub (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167d26b) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #18 0x179967e in Builtins_ConstructHandler (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x179967e) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #19 0x167f74f in Builtins_InterpreterEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167f74f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #20 0x167f74f in Builtins_InterpreterEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167f74f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #21 0x167f74f in Builtins_InterpreterEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167f74f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #22 0x16b343e in Builtins_AsyncFunctionAwaitResolveClosure (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x16b343e) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #23 0x174bcf0 in Builtins_PromiseFulfillReactionJob (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x174bcf0) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #24 0x16a4bba in Builtins_RunMicrotasks (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x16a4bba) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #25 0x167dc82 in Builtins_JSRunMicrotasksEntry (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167dc82) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #26 0xe9d659 in v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xe9d659) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #27 0xe9e25f in v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [clone .constprop.84] (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xe9e25f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #28 0xe9e969 in v8::internal::Execution::TryRunMicrotasks(v8::internal::Isolate*, v8::internal::MicrotaskQueue*, v8::internal::MaybeHandle<v8::internal::Object>*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xe9e969) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #29 0xecbe69 in v8::internal::MicrotaskQueue::RunMicrotasks(v8::internal::Isolate*) [clone .part.50] (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xecbe69) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #30 0xecc241 in v8::internal::MicrotaskQueue::PerformCheckpoint(v8::Isolate*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xecc241) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #31 0xdbaa7f in v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xdbaa7f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #32 0xdbbfbe in v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xdbbfbe) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #33 0x16fb7f8 in Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x16fb7f8) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #34 0x167f74f in Builtins_InterpreterEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167f74f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #35 0x167dd5b in Builtins_JSEntryTrampoline (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167dd5b) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #36 0x167da82 in Builtins_JSEntry (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0x167da82) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #37 0xe9d18d in v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xe9d18d) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #38 0xe9e37e in v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xe9e37e) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #39 0xd786e2 in v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xd786e2) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #40 0xabcd85 in node::InternalCallbackScope::Close() (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xabcd85) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #41 0xabce00 in node::InternalCallbackScope::~InternalCallbackScope() (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xabce00) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #42 0xb35fb8 in node::StartExecution(node::Environment*, std::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xb35fb8) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #43 0xac1316 in node::LoadEnvironment(node::Environment*, std::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xac1316) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #44 0xbc113f in node::NodeMainInstance::Run() (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xbc113f) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #45 0xb35bc7 in node::LoadSnapshotDataAndRun(node::SnapshotData const**, node::InitializationResult const*) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xb35bc7) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #46 0xb3976e in node::Start(int, char**) (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xb3976e) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)
    #47 0x7f34faa49b49 in __libc_start_call_main (/lib64/libc.so.6+0x27b49) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)
    #48 0x7f34faa49c0a in __libc_start_main_alias_2 (/lib64/libc.so.6+0x27c0a) (BuildId: 245240a31888ad5c11bbc55b18e02d87388f59a9)
    #49 0xabbded in _start (/home/ffffffff/.local/share/fnm/node-versions/v18.16.1/installation/bin/node+0xabbded) (BuildId: 1321ccb78e09b8a2eb2c74099fc19bfb3caf2063)

SUMMARY: AddressSanitizer: alloc-dealloc-mismatch (/usr/lib64/libasan.so.8.0.0+0xd7fc8) (BuildId: dc689b05ca2577037af24700212bb5cce1f91c8a) in __interceptor_free.part.0
==18439==HINT: if you don't care about these errors you may set ASAN_OPTIONS=alloc_dealloc_mismatch=0
==18439==ABORTING

The trace suggests that when creating compressed values, operator new[] is used: https://github.com/kriszyp/lmdb-js/blob/6e4146d635a66b360f6b94f746f948f2a0b2bf3d/src/compression.cpp#L123-L125

but when freeing it, free is used

https://github.com/kriszyp/lmdb-js/blob/6e4146d635a66b360f6b94f746f948f2a0b2bf3d/src/writer.cpp#L297-L299 In this context, I would assume that there is no immediate problem as it's just an array, but with a more complex type this would result in the destructor not being ran.

Is this undefined behavior which should be fixed, or just something for me to ignore in the results?

kriszyp commented 11 months ago

FYI, this should have been addressed in 2.8.3.

cxcorp commented 11 months ago

Great! Thanks for the heads-up. By the way, should it be delete[] as it's allocated with new []? I'm not too brushed up with C++.