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 >
Text File  |  1991-07-09  |  750b  |  40 lines

  1. /* These "wrappers" add logging code to both
  2.    malloc() and free(). DEBUG must be defined
  3.    before this file is #included, or the wrappers
  4.    will be ignored
  5.  
  6.    The HWRAPPER definitions
  7.    protect against unintentional duplicate inclusions.
  8. */   
  9.  
  10. #ifndef HWRAPPER
  11. #ifdef DEBUG
  12. #define HWRAPPER
  13. int count;
  14. FILE * log;
  15.  
  16. void my_free(void * tree)
  17. {
  18.     if (log == NULL) log = fopen("log","w");
  19.     fprintf(log,"%p 99999 free\n",tree);
  20.         free(tree);
  21. }
  22.  
  23. void * my_alloc(size_t size)
  24. {
  25.     void * temp;
  26.  
  27.     if (log == NULL) log = fopen("log","w");
  28.     temp = (void *) malloc(size);
  29.     fprintf(log,"%p %5.5d anew\n",temp,count++);
  30.     return temp;
  31. }
  32.  
  33. #define malloc(x) my_alloc(x)
  34.  
  35. #define free(x)  my_free(x)
  36.  
  37. #endif
  38. #endif
  39.  
  40.