swordlegend / recastnavigation

Automatically exported from code.google.com/p/recastnavigation
zlib License
0 stars 0 forks source link

rcBuildCompactHeightfield memory leak #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In rcBuildCompactHeightfield, there is an early return if the spans fail to
allocate.

if (!chf.spans)
{
    if (rcGetLog())
        rcGetLog()->log(RC_LOG_ERROR, "rcBuildCompactHeightfield: Out of memory
'chf.spans' (%d)", spanCount);
    return false;
}

Should probably add a delete [] chf.cells; before the return to free the
memory allocated above the spans allocation.

Original issue reported on code.google.com by jswig...@gmail.com on 26 Aug 2009 at 5:08

GoogleCodeExporter commented 9 years ago
compact heightfield deletes the data on its' destructor. That should not leak 
memory.
There are few other functions which may leak memory upon failure. I'm patching 
them
as I go.

Original comment by memono...@gmail.com on 26 Aug 2009 at 11:58

GoogleCodeExporter commented 9 years ago
Yes but if the function fails, and the user frees memory and tries again on the 
same
object, there will be a leak. It's awkward IMO for the user to have to know 
that they
must delete the object and re-create it in order to not leak memory.

In fact, in my local copy I have added clear() functions to all the recast and 
detour
classes so that I don't have to new them all the time. The destructor calls the 
clear
function to do its cleanup, but I can also use it to reset the object to a known
state that may be used again. I personally prefer this, as opposed to new-ing 
and
deleting things.

Original comment by jswig...@gmail.com on 27 Aug 2009 at 2:03