memcheck.txt
snippets · 1.9 KB · 2010-03-30
Memory leak tracking note by Garry Turkington (memcheck).
Download « Back to the snippets list
From: Garry Turkington <gary@reddwarf.qub.ac.uk>
Now something constructive.. as has been seen here I've been tracking
down a large memory leak recently, which is now officillly squashed.
During the process of finding it though I got fed up with liberally
sprinkling the code with log/bug messages, and came up with this addition
to interpret() which I find useful. Basically it compares the number of
allocated strings and perm blocks after a command is executed to the
number prior to execution and if there has been an increase flags this on
a new wiznet channel. Now, the observant among you will notice that this
will flag a hell of a lot of olc commands which by their very nature
allocate new memory, plus lots of common commands which during their
execution may need a block of a size currently not around so it's
allocated. This in mind though, seeing a command that shouldnt be
alocating flagging on wiznet say 3 times in a row canbe a pretty darn good
indication that maybe you should look at the code. Your mileage may of
course vary.
You'll need to create a new wiznet channel and also make nAllocString and
nAllocPerm accessible in interp.c
At the top of interpret()
int string_count = nAllocString ;
int perm_count = nAllocPerm ;
char cmd_copy[MAX_INPUT_LENGTH] ;
char buf[MAX_STRING_LENGTH] ;
then somewhere before the command is processed..
strcpy(cmd_copy, argument) ;
then after the command is dispatched:
if (string_count < nAllocString)
{
sprintf(buf,
"Memcheck : Increase in strings :: %s : %s", ch->name, cmd_copy) ;
wiznet(buf, NULL, NULL, WIZ_MEMCHECK,0,0) ;
}
if (perm_count < nAllocPerm)
{
sprintf(buf,
"Increase in perms :: %s : %s", ch->name, cmd_copy) ;
wiznet(buf, NULL, NULL, WIZ_MEMCHECK, 0,0) ;
}
And that should do it.. it's helped me find some little faux pas from the
early days of my Rom coding when I obviously didn't understand memory
recycling half as well as I thought I did. :)
Garry