.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Programming (http://forums.bots-united.com/forumdisplay.php?f=25)
-   -   Finding leaks (http://forums.bots-united.com/showthread.php?t=3610)

Maleficus 18-02-2005 10:02

Finding leaks
 
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 11:21

Re: Finding leaks
 
mostly its with indexes. Ie:

Code:


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:

Code:


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.

koraX 18-02-2005 11:57

Re: Finding leaks
 
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 01:29

Re: Finding leaks
 
Quote:

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". :)

Quote:

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/inde...on=file&id=254


All times are GMT +2. The time now is 00:36.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.