mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-12 15:33:23 -05:00
Add function to let the memory watcher know about memory allocated in libraries
This commit is contained in:
parent
3993a75dbf
commit
f7e16d22ab
27
src/err.c
27
src/err.c
@ -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;
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user