Valgrind errors even though all heap blocks were freed

Viewed 12229

I have recently developed a habit of running all of my programs through valgrind to check for memory leaks, but most of its results have been a bit cryptic for me.

For my latest run, valgrind -v gave me:

All heap blocks were freed -- no leaks are possible

That means my program's covered for memory leaks, right?

So what does this error mean? Is my program not reading certain memory blocks correctly?

ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 14 from 9)

1 errors in context 1 of 1:
Invalid read of size 4
   at 0x804885B: findPos (in /home/a.out)
   by 0xADD918: start_thread (pthread_create.c:301)
   by 0xA26CCD: clone (clone.S:133)
 Address 0x4a27108 is 0 bytes after a block of size 40 alloc'd
   at 0x4005BDC: malloc (vg_replace_malloc.c:195)
   by 0x804892F: readInput (in /home/a.out)
   by 0xADD918: start_thread (pthread_create.c:301)
   by 0xA26CCD: clone (clone.S:133)

used_suppression:     14 dl-hack3-cond-1

Also, what are the so-called "suppressed" errors here?

4 Answers

If you are getting below error:- "Invalid read of size 4"

Are you freeing memory before and then go to next argument? I am also getting error because in linked list I am freeing memory first and then go to next element. Below is my code snippet where I am getting error -

void free_memory(Llist **head_ref)
{
    Llist *current=NULL;

    current=*head_ref;
    while(*head_ref != NULL)
    {
        current=*head_ref;
        free(current);
        current=NULL;
        (*head_ref)=(*head_ref)->next;
    }
}

After changes below is my code snippet -

void free_memory(Llist **head_ref)
{
    Llist *current=NULL;
    current=*head_ref;
    while(*head_ref != NULL)
    {
        current=*head_ref;
        (*head_ref)=(*head_ref)->next;
        free(current);
        current=NULL;
     }
 }
Related