I ran valgrind in the code indicated in the question (after compiling with the '-g' option) using the operator (valgrind --leak-check=full --show-reachable=yes --track-origins=yes ./test)
The output is below
==59142== Memcheck, a memory error detector
==59142== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==59142== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==59142== Command: ./test
==59142==
==59142==
==59142== HEAP SUMMARY:
==59142== in use at exit: 4 bytes in 1 blocks
==59142== total heap usage: 1 allocs, 0 frees, 4 bytes allocated
==59142==
==59142== 4 bytes in 1 blocks are definitely lost in loss record 1 of 1
==59142== at 0x4A075BC: operator new(unsigned long) (vg_replace_malloc.c:298)
==59142== by 0x4006D3: testfunc() (test.cpp:7)
==59142== by 0x4006EF: main (test.cpp:13)
==59142==
==59142== LEAK SUMMARY:
==59142== definitely lost: 4 bytes in 1 blocks
==59142== indirectly lost: 0 bytes in 0 blocks
==59142== possibly lost: 0 bytes in 0 blocks
==59142== still reachable: 0 bytes in 0 blocks
==59142== suppressed: 0 bytes in 0 blocks
==59142==
==59142== For counts of detected and suppressed errors, rerun with: -v
==59142== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 6 from 6)
This clearly demonstrates that a memory leak is occurring.
source
share