Why am I getting this memory access error 'double free or corruption'?

好久不见. 提交于 2019-12-03 03:25:00

It looks like you are trying to free memory that has already been freed or was dereferenced.

Link your program with efence or run it with valgrind.

This will tell you where your pointer gets dereferenced.

Arun Taylor

Memory corruption is usually caused by writing beyond the end of allocated memory, and often it is by one byte because someone forgot to add one byte needed for the null to terminate a string.

Double free means free(x) was called twice in a row with the same value of x. Somewhere in your code free(x) is called and then most likely in another piece of code free(x) is called again.

The easiest way to isolate the problem is to use gdb and observe what is happening as you step through your code.

In your my_function code above, there are no calls to malloc or free. The zeros buffer is on the stack and the while loop does not write beyond the end of buffer. The problem is in some other part of the code. How long it would take to fix the problem(s) depends on how many places malloc/free/strdup etc. are called from.

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