RapidXML 导致的 crash 问题

【问题描述】


CentOS 6.3下,某个C++应用程序用RapidXML库读取XML文件,读取结果正确,但是读取完成之后几秒钟,该应用程序crash。coredump中call stack已乱。


【观察结果】

  • 将RapidXML 读取XML文件的部分代码,用hardcode取代,不crash
  • 将RapidXML 的 rapidxml.hpp 中的 memory_pool::m_static_memory[RAPIDXML_STATIC_POOL_SIZE] 的大小,即 RAPIDXML_STATIC_POOL_SIZE,从默认的 64K 改成 4K,不crash

  • 用 tinyxml 取代 rapidxml,不crash

【rapidxml 的 stack overflow 问题】


https://svn.boost.org/trac/boost/ticket/9224提到和我们类似的问题。有人给出以下分析和建议:


However, there is another option: you're saying MIPS, so I assume that you're talking abouta machine with very limited memory, and also very little protection.This static array, by default, occupies 64k of stack space. Is it possible that you're simply observing a stack overflow that isn't properly diagnosed, and the static buffer overlays the stack of another thread?
Please try redefining BOOST_PROPERTY_TREE_RAPIDXML_STATIC_POOL_SIZE to a smaller value in your project and see if that fixes the problem.

即,栈上的m_static_memory数组分配过大导致stack overflow,建议将RAPIDXML_STATIC_POOL_SIZE调小


然而,我们观察到的结果不像是stack overflow,因为 ulimit -s 是10M,即使改成了20M也crash。因此,我们遇到的crash像是内存非法访问了。


【解决】


将 RAPIDXML_STATIC_POOL_SIZE 调小并不能从根本上解决 crash 的根源,因此,建议将 rapidxml 换成 tinyxml


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值