From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: malloc() bug? Date: Tue, 02 Dec 1997 13:17:11 -0500 Organization: Cornell University http://www.cornell.edu Lines: 42 Sender: asu1 AT cornell DOT edu (Verified) Message-ID: <348450A7.7D2C5F5C@cornell.edu> References: <97Nov27.183707gmt+0100 DOT 17029 AT internet01 DOT amc DOT de> <34844052 DOT 6481925 AT news DOT flash DOT net> NNTP-Posting-Host: cu-dialup-0047.cit.cornell.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk jstuder AT flash DOT net wrote: > > On Thu, 27 Nov 1997 16:35:47 GMT, Christopher Croughton > wrote: > > >Try tracing each malloc() and free(). > > > >Chris C > Is there any 'easier' way to trace each malloc and free? I am not > sure I am freeing everything like I want to and wondered if there was > any easier way of tracing rather than looking for each malloc and free > line by line. > write wrapper functions my_debug_malloc, my_debug_realloc, my_debug_free do a #ifdef DEBUG #define malloc my_debug_malloc #define realloc my_debug_realloc #define free my_debug_free e.g. void* my_debug_malloc(size_t n) { char *p; fprintf(debug_file, "Request for %lu bytes:", n); p = malloc(n); fprintf(debug_file, "Allocated at %p\n", p); return p; } this is probably no the best way to implement this, but if all you are doing is to match up malloc's and free's its quick, and works ok. -- ---------------------------------------------------------------------- A. Sinan Unur Department of Policy Analysis and Management, College of Human Ecology, Cornell University, Ithaca, NY 14853, USA mailto:sinan DOT unur AT cornell DOT edu http://www.people.cornell.edu/pages/asu1/