Date: Fri, 19 Sep 1997 09:23:36 +0200 (SAT) From: Graham Wheeler <gram@cdsec.com> To: tlambert@primenet.com (Terry Lambert) Cc: hackers@freebsd.org Subject: Re: Bug in malloc/free (was: Memory leak in getservbyXXX?) Message-ID: <199709190723.JAA01749@cdsec.com> In-Reply-To: <199709182114.OAA13613@usr03.primenet.com> from "Terry Lambert" at Sep 18, 97 09:14:40 pm
next in thread | previous in thread | raw e-mail | index | archive | help
> > > Well, then maybe you'll find the code below useful. It isn't Purify, but > > then it doesn't cost anything near the price 8-). I'd use it > > myself now, except that these days I write everything in C++. Mostly I'm > > happy about that, but not right now... > > You can replace you "new" and "delete" functions; you knew that, right? Yes - but what I really want is a drop-in replacement using the preprocessor, like the C library does, so that I can use __FILE__ and __LINE__ macros to get the location of the new/delete: that is the tricky part. One could write a base class that all others must inherit, override it's new and delete operators, and use the placement mechanism to pass the file and line number arguments through. But that means changing all calls to new/delete with macros, so it isn't `drop-in'. Also, all dynamic allocations of base types (like char or int arrays) would still be excluded, unless encapsulated in a class. And arrays of objects would also be messy. So with a lot of work one could get some of the functionality of the C debug library, but it would hardly be a `drop-in' solution. I do have a MemTrace class and a TRACE macro which, with not too much effort, writes a log of all allocations and deletes to a file, which can then be run through a postprocessor to show me bad deletes and memory leaks, but again, this doesn't help with overruns. > > --------- gwtest.c ------------------------------------------------------ > > [ ... ] > > > void doubleFreeTest(void) > > { > > heap_ptr p = malloc(10); > > free(p); > > free(p); > > } > > How about: > > heap_ptr p = malloc( 20); > heap_ptr q, r; > free(p); > q = malloc(10) > r = malloc( 10); > free(p); > > ? 8-). I'll have to try it and see... -- Dr Graham Wheeler E-mail: gram@cdsec.com Citadel Data Security Phone: +27(21)23-6065/6/7 Internet/Intranet Network Specialists Mobile: +27(83)-253-9864 Firewalls/Virtual Private Networks Fax: +27(21)24-3656 Data Security Products WWW: http://www.cdsec.com/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199709190723.JAA01749>