[ODE] memory leak from redundant allocation in dBodyCreate

Riley Lark rileylark at gmail.com
Mon Dec 4 19:25:44 MST 2006

> I changed line 261 and 262 to this:
>    if(!b->average_lvel_buffer)
>        b->average_lvel_buffer = new dVector3[b->adis.average_samples];
>    if(!b->average_avel_buffer)
>        b->average_avel_buffer = new dVector3[b->adis.average_samples];
> so the buffer will not be recreated.
> would you agree?

I am generally wary of having the allocation happen in two different
functions, though, and wonder if it would be better to remove the
allocation from dBodyCreate altogether.  My main hesitation is that
the code above tests average_lvel_buffer against NULL, but doesn't
make sure that average_lvel_buffer has enough room for
adis.average_samples many dVector3s.  I know that right now
average_samples can never change between the two allocations, but if
later average_samples is made to change somewhere in the

but yes, your code is a safer fix in the short term (and it is what I
did in my code).


More information about the ODE mailing list