Add function to let the memory watcher know about memory allocated in libraries

This commit is contained in:
Ron Pedde 2003-11-26 06:10:21 +00:00
parent 3993a75dbf
commit f7e16d22ab
2 changed files with 28 additions and 1 deletions

View File

@ -134,6 +134,31 @@ int err_unlock_mutex(void) {
return 0;
}
/*
* Let the leak detector know about a chunk of memory
* that needs to be freed, but came from an external library
*/
void err_notify(char *file, int line, void *ptr) {
ERR_LEAK *pnew;
pnew=(ERR_LEAK*)malloc(sizeof(ERR_LEAK));
if(!pnew)
log_err(1,"Error: cannot allocate leak struct\n");
if(err_lock_mutex())
log_err(1,"Error: cannot lock error mutex\n");
pnew->file=file;
pnew->line=line;
pnew->size=0;
pnew->ptr=ptr;
pnew->next=err_leak.next;
err_leak.next=pnew;
err_unlock_mutex();
}
/*
* err_malloc
*
@ -199,7 +224,7 @@ void err_free(char *file, int line, void *ptr) {
}
if(!current) {
log_err(0,"Attempt to free unallocated memory: %s, %d\n",file,line);
log_err(1,"Attempt to free unallocated memory: %s, %d\n",file,line);
} else {
free(current->ptr);
last->next=current->next;

View File

@ -48,12 +48,14 @@ extern void log_setdest(char *app, int destination);
# define malloc(x) err_malloc(__FILE__,__LINE__,x)
# define strdup(x) err_strdup(__FILE__,__LINE__,x)
# define free(x) err_free(__FILE__,__LINE__,x)
# define MEMNOTIFY(x) err_notify(__FILE__,__LINE__,x)
# endif /* __IN_ERR__ */
extern void *err_malloc(char *file, int line, size_t size);
extern char *err_strdup(char *file, int line, const char *str);
extern void err_free(char *file, int line, void *ptr);
extern void err_notify(char *file, int line, void *ptr);
extern void err_leakcheck(void);
#endif /* DEBUG */