OgreResourceProvider memory leak
Posted: Thu Dec 16, 2004 00:40
I've spotted a memory leak while using OgreResourceProvider. I know _Mental_ had hinted at some leaks about a week and a half ago but then mentioned that they were corrected. I've waited since the 9 Dec to see if the fixes would come through on anonymous cvs but still nothing yet. I'll give a quick rundown on what I found since this maybe a different leak.
The code where the leak originates is the following:
When MemBufInputSource is created, false is passed for adoptBuffer. Passing false for adoptBuffer means that when the instance of MemBufInputSource is deleted, it will not delete the buffer passed in the constructor ie input.getPtr(). When "output" is destroyed later on, it only deletes the instance of MemBufInputSource ie the pointer to the instance passed using output.setData(mInputSource) and not the memory that was allocated in Ogre::DataChunk::allocate (line 55: new uchar[mSize + 1];).
I did find a solution but I think either CE or _Mental_ should verify this before I put my foot in my mouth by posting the solution I came up with.
The code where the leak originates is the following:
Code: Select all
void OgreResourceProvider::loadInputSourceContainer(const String& filename, InputSourceContainer& output)
{
Ogre::DataChunk input;
if( !Ogre::ArchiveManager::getSingleton()._findResourceData(
filename.c_str(), input ) )
{
throw InvalidRequestException((utf8*)
"Scheme::Scheme - Filename supplied for Scheme loading must be valid");
}
XERCES_CPP_NAMESPACE_USE
InputSource* mInputSource = new MemBufInputSource(input.getPtr(), input.getSize(), filename.c_str(), false);
output.setData(mInputSource);
}
When MemBufInputSource is created, false is passed for adoptBuffer. Passing false for adoptBuffer means that when the instance of MemBufInputSource is deleted, it will not delete the buffer passed in the constructor ie input.getPtr(). When "output" is destroyed later on, it only deletes the instance of MemBufInputSource ie the pointer to the instance passed using output.setData(mInputSource) and not the memory that was allocated in Ogre::DataChunk::allocate (line 55: new uchar[mSize + 1];).
I did find a solution but I think either CE or _Mental_ should verify this before I put my foot in my mouth by posting the solution I came up with.