Listing 1 (memdebug.h)

/* memdebug.h header file for debugging versions of malloc,
 * calloc, realloc and free. To use: place #define DEBUG
 * line before #include "memdebug.h" in program to debug.
 * Copyright 1990 by Wahhab Baldwin. Permission to copy
 * freely granted if this notice is included.
*/

#ifndef _SIZE_T_DEFINED
typedef unsigned int size_t;
#define _SIZE_T_DEFINED
#endif

typedef struct memchain {
   unsigned int line;
   unsigned short module_ix;
   size_t bytes;
   struct memchain *next;
   struct memchain *prev;
   unsigned int sentinal;
} MEMCHAIN, *PMEMCHAIN;

#if defined(DEBUG)
/* redefine normal library memory calls */
#define malloc(x) d_malloc(x, _FILE_, _LINE_ )
#define calloc(x, y) d_calloc(x, y, _FILE_, _LINE_)
#define realloc(x, y) d_realloc(x, y, _FILE_, _LINE_)
#define free(x) d_free(x, _FILE_, _LINE_)

/* function prototypes */
void *d_malloc(size_t bytes, char *module, int line);
void *d_calloc(size_t n, size_t bytes, char *module,
             int line);
void *d_realloc(void *rptr, size_t bytes, char *module,
             int line);
void *d_showmem(void);
#endif
/* end of memdebug.h */