View Full Version : Finding leaks
Maleficus
18-02-2005, 11:02
I recently discovered a leak of some kind in Fritz. It doesn't do it always, and usually only after a while. It always crashes in the .exe, with an error msg about "referencing memory that could not be read".
I've run Fritz with various monitors running, and the Private Bytes count and the Handle counts for the game never increase, so I'm wondering if anyone with some C experience has some ideas where would be the "usual suspects" to look for. I've checked my pointers and strucs, they all look good.
I don't alloc any memory, don't play around with the game's internal pointers/strucs (much.....).
Its the randomness of the crash, and the fact that no memory or handles are used, that really confuses me ATM. ???:(
stefanhendriks
18-02-2005, 12:21
mostly its with indexes. Ie:
int test[10];
for (int i=0; i < 10; i++)
test[i]=-1;
// and this is bad
test[i] = 0; // means i = 10 , ouch
Or simply having a bigger content in a char then possible:
char msg[10];
// this 11 characters + carriage return! (so needs 12)
sprintf(msg, "Hello world\n");
its within all these little obvious things. Easy to overlook. Perhaps you can use assert to track down suspecious variables.
I had very nasty bug in my bot recently. It ran fine on release mode, however it crashed in debug mode. It crashed bit randomly and after some specific sequence of commands.
Nevermind I said, I'll set breakpoints and I'll find out the problem. However when hl ran under debugger, there was no crash.
Nevermind I said, I have pretty cool logging system in my bot, I'll log code and debug it that way to find incriminated code.
However I was using buffer to speed up logging and after the crash, buffer was not written to disk.
Nevermind I said, I'll set buffer size to 0 and I'll see what was logged last before crash, I'd done it couple of times.
However after I set it to 0, crash was gone.
I was like wtf. After 4 hours I've finally found the problem. I had an array of size about 20 or so where I stored clients weapon when message came, but I didn't check bounds and one message came with index 255 9_9
After that I use std::vector whenever I can :)
electric fence may help you with dynamic memory : http://perens.com/FreeSoftware/
Whistler
21-02-2005, 02:29
I had very nasty bug in my bot recently. It ran fine on release mode, however it crashed in debug mode. It crashed bit randomly and after some specific sequence of commands.
at the first when I was messing around POD-Bot source code I had the first time (I was using MSVC6 at that time), but the problem disappeared if I changed one item in the project options from "Multithread Debug" to "Multithread". :)
electric fence may help you with dynamic memory : http://perens.com/FreeSoftware/
there is also a small utility from Netscape (now Mozilla.org):
http://filebase.bots-united.com/index.php?action=file&id=254
vBulletin® v3.7.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.