Getline with g++ and gcc

626 views Asked by At

sorry if it's already here somewhere, i didn't find it.

My simple program is:

int main(){

size_t n = 0;

char *line = NULL;

getline(&line,&n,stdin);

free(line);

return 0;
}

Valgrind output:

==7300== HEAP SUMMARY:
==7300==     in use at exit: 72,704 bytes in 1 blocks
==7300==   total heap usage: 2 allocs, 1 frees, 72,824 bytes allocated
==7300==

I need to compile using g++ -g -o -Wall -pedantic. When i compile using gcc, problem disappears.

I'd like to ask why getline allocates 2 blocks of memory and how to free the other one.

Thanks a lot!

1

There are 1 answers

0
Armali On

This problem was caused by gcc version 5, which is kinda buggy. Update to version 6 helped. – Cart