I am going to try to ask this question without supplying too much source code because all the relevant bits add up to a bunch. The key (I think?) objects involved are

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);

the boost::function mf1 is used as a callback function for a minimisation routine (o2scl::ool_mmin_spg) but I don't think the problem I am having is specific to that. The code runs with the calls to the ool_mmin_spg.mmin() function which makes use of mf1 as a callback and seems to run without errors. Then I get this lovely message

* glibc detected * ./test: corrupted double-linked list: 0x0000000001e9fb20 ***

followed by a backtrace and memory map. The relevant line of the backtrace seems to be

#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<1>, boost::arg<2>, boost::arg<3>, boost::arg<4> > > >::manage (in_buffer=, out_buffer=warning: (Internal error: pc 0x41d270 in read in psymtab, but not in symtab.)

I deduce that there is a problem freeing up memory from the boost::function, but other than that I am lost. Are there any pointers on trying to debug glibc "corrupted double-linked list" errors? I've found a few references on google but all have seemed to address very specific problems. Please let me know if more detailed code snips are required and thanks for your time!

+4  A: 

Run the program through valgrind. That'll give you a stack trace when the memory gets corrupted (as well as a stack trace corresponding to the history of that piece of memory eg. where it was created or, if it was deleted, where it was destroyed).


I'm the O2scl writer and didn't see this post until now. I looked over the spg minimizer a bit just to make sure, and I didn't see anything clearly wrong, but I admit I've never tried using boost::function and o2scl together in this way. I'll continue to look things over a bit, but let me know if you figure things out.

thanks for your comment! I resolved the problem, it wasn't an issue with o2scl but with an object that the boost function was referencing going out of scope before it was needed.