Valgrind finds memory leaks, crtdbg doesn't

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)




the class looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>

using namespace std;

class stackTemplate
{
public:
    stackTemplate(int);
    ~stackTemplate();
    bool isFull();
    bool isEmpty();
    void push(int);
    void pop(int &);

private:
    int *stackArray;
    int stackSize;
    int top;
};

stackTemplate::stackTemplate(int stackSize)
{
    top = -1;
    this->stackSize = stackSize;
    stackArray = new int[stackSize];
}

stackTemplate::~stackTemplate()
{
  delete [] stackArray;
  stackArray = NULL;
}


bool stackTemplate::isFull()
{
    if (top == stackSize - 1)
        return true;

    else
        return false;
}


bool stackTemplate::isEmpty()
{
    if (top == -1)
        return true;

    else
        return false;
}

void stackTemplate::push(int value)
{

    if (!isFull())
    {
        stackArray[top + 1] = value;
        top++;
    }
}

void stackTemplate::pop(int &value)
{
    if (!isEmpty())
    {
        value = stackArray[top];
        stackArray[top] = NULL;
        top--;
    }
}
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?
I asked the same thing...
So is there any other application that checks for leaks which is better than valgrind?
http://www.linuxjournal.com/article/6556

Or write your own ;)

My favourite one is no longer available, unfortunately.
Thanks!
Topic archived. No new replies allowed.