Hi
After attending a couple of C++ courses, using visual C++, I'm trying to learn how to use valgrind instead of crtdbg for finding leakchecks, since I prefer Linux over windows.
Now I'm doing a book excersize where I'm creating a stack class. When I run the driver program crtdbg doesn't find leaks, but valgrind do:
hadoque@meitner:~/skola/c$ valgrind --tool=memcheck --leak-check=full ./driver
==4562== Memcheck, a memory error detector
==4562== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==4562== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info
==4562== Command: ./driver
==4562==
---Uninteresting program output ---
==4562==
==4562== HEAP SUMMARY:
==4562== in use at exit: 40 bytes in 1 blocks
==4562== total heap usage: 1 allocs, 0 frees, 40 bytes allocated
==4562==
==4562== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1
==4562== at 0x4C255E4: operator new[](unsigned long) (vg_replace_malloc.c:264)
==4562== by 0x40091A: stackTemplate::stackTemplate(int) (in /home/hadoque/Dropbox/skola/c/driver)
==4562== by 0x400A59: main (in /home/hadoque/Dropbox/skola/c/driver)
==4562==
==4562== LEAK SUMMARY:
==4562== definitely lost: 40 bytes in 1 blocks
==4562== indirectly lost: 0 bytes in 0 blocks
==4562== possibly lost: 0 bytes in 0 blocks
==4562== still reachable: 0 bytes in 0 blocks
==4562== suppressed: 0 bytes in 0 blocks
==4562==
==4562== For counts of detected and suppressed errors, rerun with: -v
==4562== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)
Did you define a copy constructor and assignment operator? The compiler generated ones will not perform a deep copy. Also, if I recall correctly, valgrind finds a number of false alarms when using the STL...
No, no copy constructor or assignment op, but I haven't done any copying in the driver, so that doesn't explain it. All I've done in the driver is use the constructor once, nothing more.
If valgrind produces false positives it would explain it, but how do I know what is false and what is actual leakage in the future?