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

Peng Yu via llvm-dev llvm-dev at lists.llvm.org
Tue May 11 14:15:11 PDT 2021


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


More information about the llvm-dev mailing list