Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22031

Valgrind reports memory leak on freed pointer after getline from stdin

$
0
0

Having this code:

#include <stdlib.h>
#include <stdio.h>
void main()
{   
    char *line = calloc(1024, 1);
    size_t size = 0;
    getline(&line, &size, stdin);
    free(line);
}

Valgrind complains:

==5931== HEAP SUMMARY:
==5931==     in use at exit: 1,024 bytes in 1 blocks
==5931==   total heap usage: 3 allocs, 2 frees, 2,168 bytes allocated
==5931== 
==5931== 1,024 bytes in 1 blocks are definitely lost in loss record 1 of 1
==5931==    at 0x4837B65: calloc (vg_replace_malloc.c:752)
==5931==    by 0x10916B: main (test.c:5)
==5931== 
==5931== LEAK SUMMARY:
==5931==    definitely lost: 1,024 bytes in 1 blocks

I have seen other related posts but could not find an answer to this particular case :/


Viewing all articles
Browse latest Browse all 22031

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>