Robert777
Robert777

Reputation: 801

Why isn't Valgrind Working?

I'm new to C, Ubuntu and decided to install Valgrind and test it on this simple C code:

#include <stdio.h>

int *p;

int main(void) {
    p = calloc(100, sizeof(int));
    return 0;
}

I've placed this code inside sum.c file and compiled it. Then I've typed:

valgrind --tool=memcheck --leak-check=yes sum

in the terminal window and this is what I got:

enter image description here

I don't know if it keep looping or just get stuck, but it would stay this way until I click ctrl+d to stop it and this is what I get:

enter image description here

Am I doing something wrong ? Why can't I see that I've got a memory leak ?

By the way, this is Ubuntu version 11.04.

Thanks in advance

Upvotes: 0

Views: 3649

Answers (2)

cnicutar
cnicutar

Reputation: 182609

Notice the

00000     0

You're running /usr/bin/sum instead of your own executable, because you didn't say ./sum. That's why you have to hit C-d: sum(1) waits until EOF.


As a side note, it's highly likely you won't get a leak reported, but rather a "memory still reachable".

Upvotes: 7

Pankrates
Pankrates

Reputation: 3094

You probably need to use the following notation

valgrind --tool=memcheck --leak-check=yes ./sum

That is if 'sum' is the name of your executable. Notice the addition of './'

Upvotes: 2

Related Questions