Issue 55682
Summary code coverage leaks string when using dlopen
Labels new issue
Assignees
Reporter nolange
    If you use a custom filename for the profile data, then every loaded library will allocate a string for the name in [InstrProfilingFile.c](https://github.com/llvm/llvm-project/blob/857c612d899f271402470d4026d2e3be1dce53a4/compiler-rt/lib/profile/InstrProfilingFile.c#L713).

The problem is that this will never be free'd.

I am using llvm 14.0 x64_64 from [debian](https://tracker.debian.org/pkg/llvm-toolchain-14).

Steps to reproduce (and have the address sanitizer report the leak):

```bash
CLARGS="-stdlib=libc++ -stdlib=libc++ -fuse-ld=lld -rtlib=compiler-rt -fsanitize=address -fsanitize=undefined -fprofile-instr-generate -fcoverage-mapping "

echo "int foo() {return 0;}" | clang++ $CLARGS  -shared -o libfoo.so -x c++ -

printf '#include <dlfcn.h>\nint main() {dlclose(dlopen("libfoo.so", RTLD_LOCAL | RTLD_NOW));}\n' | clang++  $CLARGS -rpath '$ORIGIN' -L. -ldl -o test -x c++ -
 
LLVM_PROFILE_VERBOSE=1 LLVM_PROFILE_FILE=/tmp/x.profraw ./test
```

(I opened a thread on [LLVM Discourse](https://discourse.llvm.org/t/code-coverarge-with-dynamically-loaded-libraries-moved/62048), but that seems dead and I meanwhile am sure that this is a bug)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to