1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
/*
* These are the wrappers around malloc for detailed tracing and leak
* detection. Allocation routines call RECORD_FILE_AND_LINE to record the
* filename/line number keyed on the block address in the splay tree,
* de-allocation functions call DELETE_RECORD to delete the specified block
* address and its associated file/line from the splay tree.
*/
/* Author: Mark Moraes <moraes@csri.toronto.edu> */
/*LINTLIBRARY*/
#include "defs.h"
#include "globals.h"
#include "trace.h"
RCSID("$Id: _malloc.c,v 1.1.1.1 1998/02/10 21:01:46 mea Exp $")
univptr_t
__malloc(nbytes, fname, linenum)
size_t nbytes;
const char *fname;
int linenum;
{
univptr_t cp;
PRTRACE(sprintf(_malloc_statsbuf, "%s:%d:", fname, linenum));
cp = malloc(nbytes);
RECORD_FILE_AND_LINE(cp, fname, linenum);
return(cp);
}
/* ARGSUSED if TRACE is not defined */
void
__free(cp, fname, linenum)
univptr_t cp;
const char *fname;
int linenum;
{
PRTRACE(sprintf(_malloc_statsbuf, "%s:%d:", fname, linenum));
DELETE_RECORD(cp);
free(cp);
}
univptr_t
__realloc(cp, nbytes, fname, linenum)
univptr_t cp;
size_t nbytes;
const char *fname;
int linenum;
{
univptr_t old;
PRTRACE(sprintf(_malloc_statsbuf, "%s:%d:", fname, linenum));
old = cp;
cp = realloc(cp, nbytes);
if (old != cp) {
DELETE_RECORD(old);
RECORD_FILE_AND_LINE(cp, fname, linenum);
}
return(cp);
}
univptr_t
__calloc(nelem, elsize, fname, linenum)
size_t nelem, elsize;
const char *fname;
int linenum;
{
univptr_t cp;
PRTRACE(sprintf(_malloc_statsbuf, "%s:%d:", fname, linenum));
cp = calloc(nelem, elsize);
RECORD_FILE_AND_LINE(cp, fname, linenum);
return(cp);
}
/* ARGSUSED if TRACE is not defined */
void
__cfree(cp, fname, linenum)
univptr_t cp;
const char *fname;
int linenum;
{
PRTRACE(sprintf(_malloc_statsbuf, "%s:%d:", fname, linenum));
DELETE_RECORD(cp);
/* No point calling cfree() - it just calls free() */
free(cp);
}
|