home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!mucs!m1!bevan
- From: bevan@cs.man.ac.uk (Stephen J Bevan)
- Newsgroups: comp.programming
- Subject: Re: Chasing memory leaks: tools, procedures?
- Message-ID: <BEVAN.92Jul21191607@panda.cs.man.ac.uk>
- Date: 21 Jul 92 18:16:07 GMT
- References: <1992Jul6.093355.20442@lth.se>
- <1992Jul18.203518.14496@murdoch.acc.Virginia.EDU>
- <1992Jul19.160323.8820@organpipe.uug.arizona.edu>
- <NICKEL.92Jul19184631@desaster.cs.tu-berlin.de>
- Sender: news@cs.man.ac.uk
- Organization: Department of Computer Science, University of Manchester
- Lines: 32
- In-reply-to: nickel@cs.tu-berlin.de's message of 19 Jul 92 17:46:31 GMT
-
- In article <NICKEL.92Jul19184631@desaster.cs.tu-berlin.de> nickel@cs.tu-berlin.de (Juergen Nickelsen) writes:
- In article <1992Jul19.160323.8820@organpipe.uug.arizona.edu>
- dave@cs.arizona.edu (Dave Schaumann) writes:
-
- > The definition of new is
- >
- > #define new(type) ( (type *)must_alloc(sizeof(type)) )
- >
- > and must_alloc() is just a function that calls malloc and aborts if malloc
- > returns NULL.
-
- To make this more useful, must_alloc() should also call some
- cleanup-function. For some application it is a must to have control of
- their termination, e.g. to remove temporary files, re-rename
- temporarily renamed files etc.
-
- Assuming you quit must_malloc with "exit", how about just registering
- your procedures with "atexit"? Alternately, if you really want to
- keep the things separate, how about having a malloc specific "atexit"
- and allow multiple procedures to be registered? It seems much more
- flexible to me. Of course then you can have another function which
- allows you to remove registered routines (or at least the last defined
- one). And then you can .... anyone get the feeling exception
- handling is being reinvented for the nth time :-)
-
- I've implemented some of the above in my own "must_malloc" variant,
- though I didn't go as far as a specific "atexit". It has a few other
- niceties like creating a log file of all (de)allocations so you can
- check for leaks in your program. I can make it available (by mail) if
- anybody is interested.
-
- bevan
-