Jump to content
  • Advertisement
Sign in to follow this  
_orm_

Script Based Memory Leak Found

This topic is 3000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I discovered recently that the following code will produce a memory leak with the latest AngelScript.

void run()
{
while(_run)
{
bytebuffer bb(); // here is where the leak occurs.
// bb never falls out of scope.
// the problem is corrected by putting the buffer
// object outside the loop and flushing it every iteration,
// but normally in C++, it would fall out of scope at
// the end of the loop. bytebuffer is registered as a reference
// type.
irc_event event(this);
int chars = sock.receive(bb,4098);

if(chars>0)
{
string msgstr=bb.str;
string@[] messages = split(msgstr,"\r\n");

for(int y=0;y<messages.length();y++)
{
/*for(int h=0;h<messages[y].length();h++)
{
// remove any and all newlines from the message!!!
if(messages[y][h]!=CR || messages[y][h]!=LF)
{
b.push_back(messages[y][h]);
}
}*/
event.raw_string=messages[y];
IRC_EVENT_HANDLER@ evt;
if(event.prefix=="PING")
{
events.get("PING",@evt);
evt(event);
}
if(event.prefix=="ERROR")
{
_run=false;
send_raw("QUIT\r\n");
sock.close();
}
else if(events.exists(event.command))
{
events.get(event.command,@evt);
evt(event);
}
else
{
events.get("DEFAULT",@evt);
evt(event);
}
}
}
}
}

Share this post


Link to post
Share on other sites
Advertisement
Since it is a reference type the object will survive until all references to it are released, even if the original declaration goes out of scope.

How is the socket.receive() method implemented? Is it receiving the bytebuffer by handle? If so, is it properly releasing it before returning?

Share this post


Link to post
Share on other sites
Now that you mention it, I never do add a reference to the bytebuffer. It is being received by handle.

EDIT: Yep, it was my code. Remember to Release your passed handles kids.

[Edited by - _orm_ on July 4, 2010 1:52:45 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!