如何在“检测到glibc *** free():无效指针"上强制中止操作; [英] How to force abort on "glibc detected *** free(): invalid pointer"
问题描述
在Linux环境中,当出现"glibc检测到*** free():无效的指针"错误时,如何确定是哪一行代码引起的?
In Linux environment, when getting "glibc detected *** free(): invalid pointer" errors, how do I identify which line of code is causing it?
是否有一种方法可以强制中止?我记得有一个ENV变量来控制吗?
Is there a way to force an abort? I recall there being an ENV var to control this?
如何在gdb中为glibc错误设置断点?
How to set a breakpoint in gdb for the glibc error?
推荐答案
我相信,如果将MALLOC_CHECK_
设置为2,则glibc将在检测到"free():无效指针"错误时调用abort()
.请注意环境变量名称中的下划线.
I believe if you setenv MALLOC_CHECK_
to 2, glibc will call abort()
when it detects the "free(): invalid pointer" error. Note the trailing underscore in the name of the environment variable.
如果MALLOC_CHECK_
为1,则glibc将打印"free():无效指针"(以及其他错误的类似printfs).如果MALLOC_CHECK_
为0,则glibc将静默忽略此类错误并仅返回.如果MALLOC_CHECK_
为3,则glibc将打印消息,然后调用abort()
. IE.它是一个位掩码.
If MALLOC_CHECK_
is 1 glibc will print "free(): invalid pointer" (and similar printfs for other errors). If MALLOC_CHECK_
is 0, glibc will silently ignore such errors and simply return. If MALLOC_CHECK_
is 3 glibc will print the message and then call abort()
. I.e. its a bitmask.
您还可以使用参数0-3调用mallopt(M_CHECK_ACTION, arg)
,并获得与MALLOC_CHECK_
相同的结果.
You can also call mallopt(M_CHECK_ACTION, arg)
with an argument of 0-3, and get the same result as with MALLOC_CHECK_
.
由于您看到"free():无效的指针"消息,我认为您必须已经设置了MALLOC_CHECK_
或调用mallopt()
.默认情况下,glibc不会打印这些消息.
Since you're seeing the "free(): invalid pointer" message I think you must already be setting MALLOC_CHECK_
or calling mallopt()
. By default glibc does not print those messages.
关于如何调试它,为SIGABRT
安装处理程序可能是最好的进行方法.您可以在处理程序中设置断点,也可以故意触发核心转储.
As for how to debug it, installing a handler for SIGABRT
is probably the best way to proceed. You can set a breakpoint in your handler or deliberately trigger a core dump.
这篇关于如何在“检测到glibc *** free():无效指针"上强制中止操作;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!