delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/02/19:16:46

From: "A. Sinan Unur" <sinan DOT unur AT cornell DOT edu>
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
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

jstuder AT flash DOT net wrote:
> 
> On Thu, 27 Nov 1997 16:35:47 GMT, Christopher Croughton
> <crough45 AT amc DOT de> 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019