[ODE] memory leak fix for dxGeom class

Bram Stolk bram at sara.nl
Fri Apr 28 00:29:12 MST 2006


applied to svn trunk



-----Original Message-----
From: ode-bounces at q12.org on behalf of Paul MacKenzie
Sent: Thu 4/27/2006 21:34
To: ode at q12.org
Subject: [ODE] memory leak fix for dxGeom class
 
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

_______________________________________________
ODE mailing list
ODE at q12.org
http://q12.org/mailman/listinfo/ode




More information about the ODE mailing list