Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffi/pointer_arithmetic_operators_test is failing on vm-asan-linux-release-x64 #54397

Closed
derekxu16 opened this issue Dec 18, 2023 · 6 comments
Closed
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. gardening

Comments

@derekxu16
Copy link
Member

derekxu16 commented Dec 18, 2023

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

Direct leak of 12 byte(s) in 1 object(s) allocated from:
    #0 0x5639d28de2cf in calloc ../llvm_build/tools/clang/stage2-bins/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/compiler-rt/lib/asan/asan_malloc_linux.cpp:77:3
    #1 0x7f5df8486b5a  (<unknown module>)
    #2 0x7f5df68a3df1  (<unknown module>)
    #3 0x7f5df68a316c  (<unknown module>)
    #4 0x7f5df68a2ce9  (<unknown module>)
    #5 0x7f5df68a2c25  (<unknown module>)
    #6 0x7f5df68a2b52  (<unknown module>)
    #7 0x7f5df68a1a12  (<unknown module>)
    #8 0x7f5df68a1755  (<unknown module>)
    #9 0x7f5df68a080b  (<unknown module>)
    #10 0x7f5df8482ee5  (<unknown module>)
    #11 0x5639d2d314a7 in dart::DartEntry::InvokeFunction(dart::Function const&, dart::Array const&, dart::Array const&) /b/f/w/out/ReleaseASANX64/../../runtime/vm/dart_entry.cc:125:33
    #12 0x5639d2d35c0e in dart::DartEntry::InvokeFunction(dart::Function const&, dart::Array const&) /b/f/w/out/ReleaseASANX64/../../runtime/vm/dart_entry.cc:37:10
    #13 0x5639d2d35c0e in dart::DartLibraryCalls::HandleMessage(long, dart::Instance const&) /b/f/w/out/ReleaseASANX64/../../runtime/vm/dart_entry.cc:718:28
    #14 0x5639d2da549e in dart::IsolateMessageHandler::HandleMessage(std::__2::unique_ptr<dart::Message, std::__2::default_delete<dart::Message>>) /b/f/w/out/ReleaseASANX64/../../runtime/vm/isolate.cc:1394:15
    #15 0x5639d2e242df in dart::MessageHandler::HandleMessages(dart::MonitorLocker*, bool, bool) /b/f/w/out/ReleaseASANX64/../../runtime/vm/message_handler.cc:238:16
    #16 0x5639d2e2579e in dart::MessageHandler::TaskCallback() /b/f/w/out/ReleaseASANX64/../../runtime/vm/message_handler.cc:457:18
    #17 0x5639d31d6615 in dart::ThreadPool::WorkerLoop(dart::ThreadPool::Worker*) /b/f/w/out/ReleaseASANX64/../../runtime/vm/thread_pool.cc:158:15
    #18 0x5639d31d747a in dart::ThreadPool::Worker::Main(unsigned long) /b/f/w/out/ReleaseASANX64/../../runtime/vm/thread_pool.cc:330:9
    #19 0x5639d3013103 in dart::ThreadStart(void*) /b/f/w/out/ReleaseASANX64/../../runtime/vm/os_thread_linux.cc:154:5
    #20 0x5639d28dbc38 in asan_thread_start(void*) ../llvm_build/tools/clang/stage2-bins/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/compiler-rt/lib/asan/asan_interceptors.cpp:234:28

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

--- Re-run this test:
python3 tools/test.py -n vm-asan-linux-release-x64 ffi/pointer_arithmetic_operators_test

https://ci.chromium.org/ui/p/dart/builders/ci.sandbox/vm-asan-linux-release-x64/335/overview

@dcharkes

@derekxu16 derekxu16 added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. gardening labels Dec 18, 2023
@dcharkes
Copy link
Contributor

@shikharish

void main() {
  Pointer<Int32> p = calloc<Int32>(3);
  p.value = 1;
  (p + 1).value = 2;
  (p + 2).value = 3;
  Expect.equals(1, p.value);
  p += 2;
  Expect.equals(3, p.value);
  p -= 1;
  Expect.equals(2, p.value);
  calloc.free(p); // <-- missing
}

@shikharish
Copy link
Contributor

shikharish commented Dec 18, 2023

@shikharish

void main() {
  Pointer<Int32> p = calloc<Int32>(3);
  p.value = 1;
  (p + 1).value = 2;
  (p + 2).value = 3;
  Expect.equals(1, p.value);
  p += 2;
  Expect.equals(3, p.value);
  p -= 1;
  Expect.equals(2, p.value);
  calloc.free(p); // <-- missing
}

We cannot free a pointer after we have changed its address (by doing p+=2 and then p-=1). This code would give an error.

@dcharkes
Copy link
Contributor

dcharkes commented Dec 18, 2023

Ah, yes! We need to save the original p.

@shikharish
Copy link
Contributor

shikharish commented Dec 18, 2023

Oh right. I didn't think of that while writing the test, my bad. I will upload a patch soon!

@dcharkes
Copy link
Contributor

dcharkes commented Dec 18, 2023

Thanks @shikharish !

You can add the following to the bottom of the commit message to ensure that the ASAN bots run before we land the patch:

Cq-Include-Trybots: luci.dart.try:vm-aot-asan-linux-release-x64-try,vm-asan-linux-release-x64-try

@shikharish
Copy link
Contributor

Patch uploaded: https://dart-review.googlesource.com/c/sdk/+/342460

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. gardening
Projects
None yet
Development

No branches or pull requests

3 participants