简体   繁体   English

使用G ++和GCC的Getline

[英]Getline with g++ and gcc

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: Valgrind输出:

==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 . 我需要使用g++ -g -o -Wall -pedantic进行编译。 When i compile using gcc , problem disappears. 当我使用gcc进行gcc ,问题消失了。

I'd like to ask why getline allocates 2 blocks of memory and how to free the other one. 我想问一下为什么getline分配2个内存块,以及如何释放另一个内存块。

Thanks a lot! 非常感谢!

This problem was caused by gcc version 5, which is kinda buggy. 此问题是由gcc版本5引起的,该版本有点问题。 Update to version 6 helped. 更新版本6有所帮助。 – Cart –购物车

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM