I'm guessing gsl_odeiv_step_alloc
and gsl_odeiv_step_free
are similar to malloc
and free
. In this case it's clear that you have a problem of "double free". In the following code
mySolverVec.push_back(ODESolver(myODEVec[0]));
you create a temporary ODESolver
object which allocates some memory and assigns it to the member variables d_step_ptr
and d_evolve_ptr
. The the object is copied with the default copy constructor which just does memcpy
(copies bits) into the vector. The the temporary object is destroyed and the memory is freed. When the vector mySolverVec
goes out of scope it destroys all objects inside of it. Which tries to free the same memory again and you most likely have a crash!
You should either prohibit copying of your object. In C++11 you could allow only moves and no copies. If you have to stick with the older standard then some reference counting scheme would make sense. Take a look at boost
library and specifically boost::shared_ptr
.