home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_09_10
/
9n10042a
< prev
next >
Wrap
Text File
|
1991-07-09
|
750b
|
40 lines
/* These "wrappers" add logging code to both
malloc() and free(). DEBUG must be defined
before this file is #included, or the wrappers
will be ignored
The HWRAPPER definitions
protect against unintentional duplicate inclusions.
*/
#ifndef HWRAPPER
#ifdef DEBUG
#define HWRAPPER
int count;
FILE * log;
void my_free(void * tree)
{
if (log == NULL) log = fopen("log","w");
fprintf(log,"%p 99999 free\n",tree);
free(tree);
}
void * my_alloc(size_t size)
{
void * temp;
if (log == NULL) log = fopen("log","w");
temp = (void *) malloc(size);
fprintf(log,"%p %5.5d anew\n",temp,count++);
return temp;
}
#define malloc(x) my_alloc(x)
#define free(x) my_free(x)
#endif
#endif