How to correct *** glibc detected *** error in the program [duplicate]

强颜欢笑 提交于 2019-12-04 18:51:18

The exact solution can only be provided if you show us the code. The error is however clear. The code frees memory that is not or no longer valid. That means either the address is wrong, because for example of pointer arithmetic being done on the original pointer. Or the pointer has already been freed (double free).

You are most likely trying to free a memory that wasn't dynamically allocated. Maybe you have an unnecessary free or a typo like: free(&buf) instead of free(buf).

Compile your program with -g flag and run it through debugger or memory debugger. That will show you where the error exactly happens.

It looks like you are trying to free an invalid pointer. You can run the program with a memory check program like [Valgrind][1] like so:

valgrind --tool=memcheck --leak-check=full --track-origins=yes --show-reachable=yes --log-file=val.log ./<executable> <parameters>

Look at val.log and you should be able to figure out where your memory leaks occur. Also, you can try and step through the code with gdb/ddd (debuggers). The program will fail at the spot where the segmentation fault occurs. To make the code debuggable, you will need to re-compile your code with the -g flag.

Alternatively, you could post your code here and let the community see where you are going wrong.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!