Game Development Community

Memory leak in constructTSShape

by Tony Richards · in Torque Game Engine Advanced · 08/11/2005 (8:14 am) · 6 replies

I've looked at the code a couple of times and I'm a little tired (lack of sleep... coding like a maniac ever since I got TSE :P ) but I think this is a memory leak.

in tsShape.cpp, right around line 1800 (around there, I've modified this code quite a bit so I don't know the original line number)

ResourceInstance *constructTSShape(Stream &stream)
{
   TSShape * ret = new TSShape;
   if (ret->readDTS(&stream))
      return ret;
   else
      return NULL;
}

In TSShape::readDTS() everywhere it returns false it should delete itself, or, cleaner, change constructTSShape(Stream &stream) to this:

ResourceInstance *constructTSShape(Stream &stream)
{
   TSShape * ret = new TSShape;
   if (ret->readDTS(&stream))
      return ret;
   else
   {
      delete ret;
      return NULL;
   }
}


But, since I'm an advocate of cleaner return points where possible:

ResourceInstance *constructTSShape(Stream &stream)
{
   TSShape * ret = new TSShape;
   if (!ret->readDTS(&stream))
   {
      delete ret;
      ret = NULL;
   }

   return ret;
}

The function right below it, constructMDLShape looks right, though.

Correct, or am I too tired?

About the author

I am the founder of IndieZen.org, a website dedicated to the Indie 2.0 Revolution where a number of Indie game development studios and individuals collaborate and share a suite of custom built open source game development tools and middleware.


#1
08/11/2005 (8:46 am)
Oops, ok, constructMDLShape is correct because that's mine, but doing a diff vs the HEAD, constructTSShape indeed does have a leak and it's not something I introduced.
#2
08/11/2005 (4:49 pm)
Looks like a leak case to me, thanks Tony, it's been fixed in our internal repo - it'll go out in a few days.
#3
08/15/2005 (10:56 am)
Ah, that's a bug in TGE as well I reckon. #292.
#4
08/16/2005 (5:18 pm)
Ok, fixed in TGE. Thank you Tony!
#5
08/24/2005 (8:24 am)
Hehe, I submitted this as well, what am I not to be believed then eh ;p

www.garagegames.com/mg/forums/result.thread.php?qt=31383

~neo
#6
08/24/2005 (11:23 am)
Ah, that was when I was knee deep in Atlas code and not checking the forums. Sorry I missed it! :)