Memory corruption in Crocoddyl Python bindings
This memory corruption appears when you want to run calc
or calcDiff
for a cost model. This is an example code
import crocoddyl
import pinocchio
import numpy as np
# Create Pinocchio model and data
pinocchioModel = pinocchio.buildSampleModelHumanoidRandom()
pinocchioData = pinocchioModel.createData()
# Create a state cost model and data
state = crocoddyl.StateMultibody(pinocchioModel)
activation = crocoddyl.ActivationModelQuad(state.ndx)
xref = state.zero()
costModel = crocoddyl.CostModelState(state, activation, xref, pinocchioModel.nv)
costData = costModel.createData(pinocchioData)
# Run calc
x = state.rand()
u = np.matrix(np.random.rand(pinocchioModel.nv)).T
costModel.calc(costData, x, u) # this is the line that creates the problem
# Notes about the c++ implementation that I am binding:
# - costModel constructor takes raw pointers of pinocchioModel, state and activation
# - costModel.createData takes a raw pointer of pinocchioData
# - costModel.calc takes a boost::shared_ptr of costData
# - I handle the lifetimes of those pointer using proper policies (i.e. with_custodian_and_ward and with_custodian_and_ward_postcall)
And running the following commands on Ubuntu 16.04 solved this issue:
sudo apt-get install libtcmalloc-minimal4
export LD_PRELOAD="/usr/lib/libtcmalloc_minimal.so.4"
As described here https://github.com/tensorflow/tensorflow/issues/6968#issuecomment-273959067, it seems there is a bug in malloc changes. And this issue have more than 4 years :(
@gsaurel we might need to run these commands on our CI.
Edited by Carlos Mastalli