“glibc free(): invalid next size(fast)” on vector.push_back?

删除回忆录丶 提交于 2019-12-01 09:39:26

You're probably doing an invalid write somewhere and trashing the control information kept by glibc for bookkeeping. Thus, when it tries to free things it detects abnormal conditions (unreasonable sizes to free).

What's worst about this kind of thing is that the problem doesn't manifest itself at the point where you made the real mistake so it can be quite hard to catch (it's quite common to be an off-by-one error).

Your best bet is to use a memory debugger. valgrind could be a start (since you mentioned glibc). Look for "invalid write of size..." before the glibc message.

As @cniculat sayed, try valgrind.

Another tools you can try are:

  • gcc stl debug support. If ther problem in incorrect usage of STL container, tahn compiling with D_GLIBCXX_DEBUG and -D_GLIBCXX_DEBUG_PEDANTIC may reveal the problem. In case the problem will be discovered, program will be aborted by assert(), so you'll receive error message on console.
  • Yet another option is to use google tcmalloc. It overrides malloc()/free(). Just link your appl with tcmalloc link version, and it can detect mist memory usage problems.

STL debug support and tcmalloc can be used in regular in debug builds. This way you can work as regular, while these tools will in "background" assert you if there's an error.

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