Re: [Circle] Memory problem ?

From: Ric Klaren (
Date: 08/14/96


On Tue, 13 Aug 1996, JT Rhone wrote:

> On Mon, 12 Aug 1996, Hades wrote:
> > > There is a program called dmalloc that does about the same. It can 
> > > tell you where memory was allocated that wasn't freed after the 
> > > program was shutdown (source file and line number). It's fairly easy 
> > > to trace large leaks this way.
> > > 
> > In the INSTALL file it says to link the dmalloc library to my program, but
> > gives no instructions on how to do this. Anyone out there offer a little
> > advice?
> PLEASE :) somebody who has successfully linked this library into your mud 
> give some insight on how to do so.  I've been fiddling with it for about 
> 4 or 5 hours now to no avail, but it seems as if it's exactly the thing I 
> am looking for.

I'm currently tracing all memory leaks in our mud with this lib. 

1. First of all get the distribution. Configure and compile it. 
2. Add the libdmalloc.a to the objects circle is made from (before the 
   normal c libs with malloc in them)
3. Add the dmalloc.h at the end of sysdep.h (easiest) I made a preproc 
   define for linking with this lib. Handy for turning malloc debugging 
   on and off.... like:

   #ifdef DMALLOC
   # include "dmalloc.h"
4. To your dmalloc.h you might want to add the following:

   #undef strdup
   #define strdup(str) \
      _xstrdup_leap(__FILE__, __LINE__, str)

   This to trace strdups. You also might want to 
   #define str_dup(x) strdup(x)
   Makes tracking str(_)dup's easier.
   You also might wanna make something like this for fread_string (a 
   function you won't like when you're trying to find leaks (or unfreed  
5. Do something like (with bash as shell) 
   eval `dmalloc high -l /mud/dmalloc.log -i 1`
   (make sure to get the quotes right) this sets malloc debugging to 
   max checks the internal structs of malloc every call to a malloc 
   related thing (slow) and writes a log to /mud/dmalloc.log (if it 
   don't work check the docs (I'm typing this off hand)
6. When using linux stay in this VC and run circle (within gdb is handy)
7. Telnet to the mud. Do a shutdown now (or whatever)
8. Wait a long time....
9. Wait some longer....
10. Come to the conclusion that Circle doesn't free nothin' :(
11. Start writing code to free up all memory circle uses..... Joy happy 
    NOT! ;)
12. Iterate a bit....

Just to illustrate I saved a load of the created logs. 1 was the first 10 
was the last... Here are the filesizes...

-rw-rw-r--   1 ric      mud        252866 Aug  1 00:16 dmalloc.log.1
-rw-rw-r--   1 ric      mud         22380 Aug 13 19:26 dmalloc.log.10
-rw-rw-r--   1 ric      mud        187725 Aug  1 11:49 dmalloc.log.2
-rw-rw-r--   1 ric      mud        172947 Aug  1 17:55 dmalloc.log.3
-rw-rw-r--   1 ric      mud        158281 Aug  1 18:11 dmalloc.log.4
-rw-rw-r--   1 ric      mud         49780 Aug  1 19:35 dmalloc.log.5
-rw-rw-r--   1 ric      mud         59904 Aug  2 12:18 dmalloc.log.6
-rw-rw-r--   1 ric      mud         60353 Aug  2 13:14 dmalloc.log.7
-rw-rw-r--   1 ric      mud         57008 Aug 13 18:00 dmalloc.log.8
-rw-rw-r--   1 ric      mud         38436 Aug 13 19:16 dmalloc.log.9

At the moment I got most stuff freed. I have code I'm willing to share 
but.... our mud is far from being stock code (loads of things are done in 
linked lists, socials are completely read from file etc....) The code 
might be usable (as a framework anyways) but will need a lot of rehacking 
(and I'm no stock code expert (far from) so no support from me). People 
still interested drop me a line...

Greets and enjoy or whatever...



- Ric Klaren - - -------------
``Why don't we just invite them to dinner and massacre them all when
they're drunk?''
``You heard the man. There's seven hundred thousand of them.''
``Ah? So it'd have to be something simple with pasta, then.''
From: Interesting Times by Terry Pratchet

| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   |

This archive was generated by hypermail 2b30 : 12/07/00 PST