I run valgrind --leak-check=full test.cpp in the following code
#include <iostream> int* p = new int[42]; // no leak reported int main() { p[0] = 42; // use it std::cout << p[0]; }
and no leak reported:
==37293== LEAK SUMMARY: ==37293== definitely lost: 0 bytes in 0 blocks ==37293== indirectly lost: 0 bytes in 0 blocks ==37293== possibly lost: 0 bytes in 0 blocks
Whenever I move the definition int* p = new int[42]; inside main() , so it has an automatic storage duration, valgrind detects a memory leak. Why doesn't it detect a leak of static storage objects? Did I miss something?
source share