[ODE] memory leak fix for dxGeom class
Paul MacKenzie
paul.mackenzie at simlog.com
Thu Apr 27 12:34:03 MST 2006
Hi,
I found a memory leak in the destructor for the dxGeom class, in
collision_kernel.cpp, and submitted a solution as a patch under the name
"Memory leak fix for dxGeom".
Currently the destructor is
dxGeom::~dxGeom()
{
if (parent_space) dSpaceRemove (parent_space,this);
if ((gflags & GEOM_PLACEABLE) && !body) dFreePosr(final_posr);
if (offset_posr) dFreePosr(offset_posr);
bodyRemove();
}
However, if the collision geometry has an associated body *and* an
offset, then it has its own allocated final_posr, and it should be freed
here in the destructor. If it has an associated body and *no* offset,
then final_posr points to the body and should not be deleted (refer to
dGeomSetBody() and dGeomCreateOffset() for details on how this works).
Here is a solution that removes the leak:
dxGeom::~dxGeom()
{
if (parent_space) dSpaceRemove (parent_space,this);
if ((gflags & GEOM_PLACEABLE) && (!body || (body && offset_posr)))
dFreePosr(final_posr);
if (offset_posr) dFreePosr(offset_posr);
bodyRemove();
}
Cheers,
Paul
More information about the ODE
mailing list