Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!harvard!topaz!bentley!kwh From: kwh@bentley.UUCP (KW Heuer) Newsgroups: net.lang.c,net.lang.c++ Subject: Re: oops, corrupted memory again! Message-ID: <801@bentley.UUCP> Date: Fri, 9-May-86 09:39:03 EDT Article-I.D.: bentley.801 Posted: Fri May 9 09:39:03 1986 Date-Received: Sun, 11-May-86 03:35:00 EDT References: <4495@cbrma.UUCP> <763@bentley.UUCP>, <5097@think.ARPA> Organization: AT&T Bell Laboratories, Liberty Corner Lines: 33 Xref: linus net.lang.c:8211 net.lang.c++:169 In article <5097@think.ARPA> rose@think.ARPA (John Rose) writes: >If you do have source code, here's another suggestion which has worked >very well for me. Define an circular buffer which stores a record of >the last few hundred records of malloc/free/morecore history. Make >sure your symbolic debugger can dump it for you. This trick alone >has saved me hours of debugging time on quite a few occasions. I've found the following front-end* to be very useful: char *Dalloc(n) unsigned n; { register char *p = malloc(n); fprintf(stderr, "+%8x\n", p); return (p); } void Dfree(p) char *p; { fprintf(stderr, "-%8x\n", p); free(p); } char *Drealloc(p, n) char *p; unsigned n; { fprintf(stderr, "-%8x\n", p); p = realloc(p, n); fprintf(stderr, "+%8x\n", p); return (p); } When the program terminates (normal exit or core dump), I run a consistency check on the log file to cancel out "+xxx" and "-xxx". Any unbalanced "-" is a bug. I consider an unbalanced "+" to be a bug, too, unless there are a bounded number of them and I can account for them all. Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint *It can also be built into malloc.c if you have source; this allows it to log the calls within stdio. For some applications, a special log file should be used instead of stderr.