0

Why isn't address sanitizer flagging a memory leak in this obvious memory leak? (Note that this is a googletest unittest but could also be in a main function.

TEST_F(SresTests, test){
    double* x = (double*) malloc(sizeof(double)*10);
    for (int i=0; i<10; i++){
        x[i] = 0.1;
    }
}

I'm compiling this in cmake using

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -g")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -g")

On macos using Apple Clang version 12.0.0.

CiaranWelsh
  • 7,014
  • 10
  • 53
  • 106
  • 1
    Don't forget that you need to set the environment variable `ASAN_OPTIONS=detect_leaks=1`, but it doesn't matter, since it's not supported in this version of clang. – Rob Napier Jan 29 '21 at 15:52
  • Oh. Ill go and get the latest then. Thanks for pointing that out. Also, I must have confused Apple Clang version with Clang version since I saw this and dismissed it. – CiaranWelsh Jan 29 '21 at 16:00

0 Answers0