[llvm-dev] Why leaked memory is not shown with -fsanitize=address set on macOS?

Sterling Augustine via llvm-dev llvm-dev at lists.llvm.org
Wed May 12 11:58:03 PDT 2021


I'm not set up to test lsan on macos, but I would guess that clang is
somehow not actually generating the call to malloc. Don't know how that
would happen, exactly.

Does the call to malloc actually occur?


On Tue, May 11, 2021 at 2:15 PM Peng Yu via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> See below. I don't see a memory leak error on macOS for the following
> program.
>
> What on macOS that is different from Linux makes the compiled program
> behaves differently?
>
> $ cat main.c
> #include <stdlib.h>
> #include <stdio.h>
>
> int main(int argc, char *argv[]) {
>         void *p = malloc(100);
>         printf("%p\n", p);
>         return 0;
> }
> $ clang --version
> Debian clang version 11.0.1-2
> Target: x86_64-pc-linux-gnu
> Thread model: posix
> InstalledDir: /usr/bin
> $ clang -fsanitize=address main.c
> $ ./a.out
> 0x60b0000000f0
>
> =================================================================
> ==132039==ERROR: LeakSanitizer: detected memory leaks
>
> Direct leak of 100 byte(s) in 1 object(s) allocated from:
>     #0 0x49832d in malloc (/tmp/a.out+0x49832d)
>     #1 0x4c7f6f in main (/tmp/a.out+0x4c7f6f)
>     #2 0x7fb6966a7d09 in __libc_start_main csu/../csu/libc-start.c:308:16
>
> SUMMARY: AddressSanitizer: 100 byte(s) leaked in 1 allocation(s).
>
> $ clang --version
> Apple clang version 12.0.0 (clang-1200.0.32.28)
> Target: x86_64-apple-darwin19.6.0
> Thread model: posix
> InstalledDir:
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
> $ ./a.out
> 0x60b000000040
>
> --
> Regards,
> Peng
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210512/f1a654ca/attachment.html>


More information about the llvm-dev mailing list