【问题标题】:"corrupted double-linked list" on boost::function free() [duplicate]boost::function free() 上的“损坏的双链表” [重复]
【发布时间】:2009-10-01 21:57:43
【问题描述】:

我将尝试在不提供太多源代码的情况下提出这个问题,因为所有相关位加起来就是一堆。涉及的关键(我认为?)对象是

using namespace o2scl;

typedef MSMTModel<TASensor,PosModel,target2d,ovector,ovector_const_subvector> TA_MSMTModel;
typedef MPC_funct_mfptr<MSMT_InitialState,TA_MSMTModel,MSMTFormation> MPC_TAFormation_mfptr;
typedef boost::function<int (size_t, const ovector_base&, double&, TA_MSMTModel&)> TA_mfunct;

TA_mfunct mf1 = boost::bind(&MPC_TAFormation_mfptr::mfn, f1, _1, _2, _3, _4);

boost::function mf1 用作最小化例程 (o2scl::ool_mmin_spg) 的回调函数,但我认为我遇到的问题不是特定于此。该代码通过调用 ool_mmin_spg.mmin() 函数运行,该函数使用 mf1 作为回调并且似乎运行没有错误。然后我收到了这个可爱的消息

* 检测到 glibc * ./test: 损坏的双链表:0x0000000001e9fb20 ***

后面是回溯和内存映射。回溯的相关行似乎是


#7 0x000000000041d32a in boost::detail::function::functor_manager, o2scl::ovector_const_subvector_tlate >, MSMTFormation>, unsigned long, o2scl::ovector_base_tlate const&, double&, dmect::MSMTModel, o2scl::ovector_const_subvector_tlate >&> , boost::_bi::list5, o2scl::ovector_const_subvector_tlate >, MSMTFormation> >, boost::arg, boost::arg, boost::arg, boost::arg > > >::manage (in_buffer=, out_buffer=warning: (内部错误: pc 0x41d270 in read in psymtab, but not in symtab.)


我推断从 boost::function 释放内存存在问题,但除此之外我迷路了。是否有任何关于尝试调试 glibc“损坏的双链表”错误的指示?我在谷歌上找到了一些参考资料,但似乎都解决了非常具体的问题。如果需要更详细的代码片段,请告诉我,感谢您的宝贵时间!

【问题讨论】:

    标签: c++ glibc boost-function


    【解决方案1】:

    通过 valgrind 运行程序。这将在内存损坏时为您提供堆栈跟踪(以及与该内存块的历史相对应的堆栈跟踪,例如,它是在哪里创建的,或者如果它被删除,它在哪里被销毁)。

    【讨论】:

      【解决方案2】:

      我是 O2scl 的作者,直到现在才看到这篇文章。我稍微检查了一下 spg 最小化器以确保,我没有发现任何明显错误,但我承认我从未尝试过以这种方式一起使用 boost::function 和 o2scl。我会继续仔细研究一下,如果你弄清楚了,请告诉我。

      【讨论】:

      • 感谢您的评论!我解决了这个问题,这不是 o2scl 的问题,而是 boost 函数引用的对象在需要之前超出了范围。
      猜你喜欢
      • 2016-07-01
      • 2013-12-05
      • 2015-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多