glibc堆一致性检查 [英] glibc Heap Consistency Checking

查看:244
本文介绍了glibc堆一致性检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 根据2008年的帖子(我现在找不到它), glibc堆检查在多线程环境中不起作用。现在是2010年的情况吗?

  2. 默认启用堆检查吗? (gcc 4.1.2)?我没有设置MALLOC_CHECK_,不知道调用mcheck(),但仍然有时会用backtrace获得双免费的glibc错误。也许它是由一些编译标志启用的?


解决方案

默认情况下,不使用malloc_check_或mcheck ),glibc会执行一些不会影响性能的小检查,例如在同一内存块上调用两次free()。这就是为什么你得到这些消息的一些原因,但是你不会把所有由malloc提供的消息替换成你可以通过使用MALLOC_CHECK_获得的API(这些测试做了更多的测试,但是更强的CPU密度)。你可以通过触发一个错误来检查这个错误,并且使用和不使用malloc_check_来测试它。例如,对于一个简单的双免费(),我得到双免费或腐败(顶部)或免费():无效指针错误,具体取决于我设置MALLOC_CHECK_或$。

要回答1 /问题,mcheck依赖于malloc挂钩,因为它们存在(如15年),并且这些挂钩不是线程安全的。

来源:glibc / malloc / malloc.c, http://sourceware.org/bugzilla/show_bug.cgi?id=9939


  1. According to posts from 2008 (I can't find it right now), glibc heap check doesn't work in multithreaded environment. Is it still situation now in 2010?
  2. Does heap check enabled by default? (gcc 4.1.2)? I don't set MALLOC_CHECK_, don't aware of calling mcheck(), but still sometimes receive double free glibc error with backtrace. Maybe it's enabled by some compilation flag?

解决方案

By default, without using malloc_check_ or mcheck(), glibc does some little checks that doesn't hurt the performance, like calling twice free() on the same memory chunk. That's why you are getting some of these messages, but you won't have all messages provided by the malloc substitute api you can get by using MALLOC_CHECK_ (which are doing far more tests, but far more cpu intensive too). You can check this by triggering an error, and testing it with and without malloc_check_. For example, for a simple double-free(), i get "double free or corruption (top)" or "free(): invalid pointer" errors depending whenever I set MALLOC_CHECK_ or not.

To answer the 1/ question, mcheck relies on malloc hooks since they exists (like 15 years), and those are not intended to be thread safe.

Sources: glibc/malloc/malloc.c, http://sourceware.org/bugzilla/show_bug.cgi?id=9939

这篇关于glibc堆一致性检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆