Remove custom memory debug facility

This commit is contained in:
Julien BLACHE 2009-04-01 15:58:10 +02:00
parent ca1c461419
commit 185864e799
9 changed files with 1 additions and 267 deletions

View File

@ -107,9 +107,6 @@ AC_ARG_ENABLE(ffmpeg,[ --enable-ffmpeg Enable ffmpeg transcode support],
AC_ARG_ENABLE(upnp,[ --enable-upnp Enable upnp support], AC_ARG_ENABLE(upnp,[ --enable-upnp Enable upnp support],
CPPFLAGS="${CPPFLAGS} -DUPNP"; use_upnp=true;) CPPFLAGS="${CPPFLAGS} -DUPNP"; use_upnp=true;)
AC_ARG_ENABLE(mem-debug,[ --enable-mem-debug Enable memory debugging],
CPPFLAGS="${CPPFLAGS} -DDEBUG_MEM")
AC_ARG_ENABLE(ssl,[ --enable-ssl Enable SSL support in web server], AC_ARG_ENABLE(ssl,[ --enable-ssl Enable SSL support in web server],
CPPFLAGS="${CPPFLAGS} -DUSE_SSL"; use_ssl=true; ) CPPFLAGS="${CPPFLAGS} -DUSE_SSL"; use_ssl=true; )

View File

@ -47,7 +47,7 @@ mt_daapd_SOURCES = main.c daapd.h rend.h webserver.c \
smart-parser.c smart-parser.h xml-rpc.c xml-rpc.h \ smart-parser.c smart-parser.h xml-rpc.c xml-rpc.h \
os.h ll.c ll.h conf.c conf.h compat.c compat.h util.c util.h \ os.h ll.c ll.h conf.c conf.h compat.c compat.h util.c util.h \
os-unix.h os-unix.c os.h plugin.c plugin.h db-sql-updates.c \ os-unix.h os-unix.c os.h plugin.c plugin.h db-sql-updates.c \
memdebug.c memdebug.h ssl.h io.h io.c io-errors.h io-plugin.h \ ssl.h io.h io.c io-errors.h io-plugin.h \
bsd-snprintf.c bsd-snprintf.h \ bsd-snprintf.c bsd-snprintf.h \
$(ARENDSRC) $(OGGVORBISSRC) \ $(ARENDSRC) $(OGGVORBISSRC) \
$(FLACSRC) $(MUSEPACKSRC) $(SQLITE3DB) $(SQLDB) \ $(FLACSRC) $(MUSEPACKSRC) $(SQLITE3DB) $(SQLDB) \

View File

@ -54,7 +54,6 @@
#endif #endif
#include <time.h> #include <time.h>
#include "memdebug.h" /* redefine free/malloc/etc */
#include "compat.h" #include "compat.h"
#include "webserver.h" #include "webserver.h"

View File

@ -705,7 +705,6 @@ int main(int argc, char *argv[]) {
os_deinit(); os_deinit();
io_deinit(); io_deinit();
mem_dump();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,220 +0,0 @@
/**
* memory debugging
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#include "err.h"
#include "util.h"
#ifdef DEBUG_MEM
typedef struct debugnode_t {
char *file;
int line;
int size;
void *ptr;
struct debugnode_t *next;
} DEBUGNODE;
DEBUGNODE _debug_memlist = { NULL, 0, 0, NULL, NULL };
void debug_free(char *file, int line, void *ptr);
void *debug_malloc(char *file, int line, size_t size);
void *debug_realloc(char *file, int line, void *ptr, size_t size);
void *debug_calloc(char *file, int line, size_t count, size_t size);
char *debug_strdup(char *file, int line, const char *str);
void debug_dump(void);
void *_debug_alloc_nolock(char *file, int line, size_t size);
DEBUGNODE *_debug_find_ptr(void *ptr);
void _debug_register_ptr(char *file, int line, void *ptr, size_t size);
/**
* find a ptr in the node list, assuming the list is already
* locked.
*/
DEBUGNODE *_debug_find_ptr(void *ptr) {
DEBUGNODE *prev, *current;
prev = &_debug_memlist;
current = prev->next;
while(current) {
if(current->ptr == ptr)
return current;
prev = current;
current = current->next;
}
return NULL;
}
void *_debug_alloc_nolock(char *file, int line, size_t size) {
void *ptr;
ptr = malloc(size);
if(!ptr)
DPRINTF(E_FATAL,L_MISC,"Malloc failed in _debug_alloc\n");
_debug_register_ptr(file, line, ptr, size);
return ptr;
}
void _debug_register_ptr(char *file, int line, void *ptr, size_t size) {
DEBUGNODE *pnew;
pnew = (DEBUGNODE *)malloc(sizeof(DEBUGNODE));
if(!pnew)
DPRINTF(E_FATAL,L_MISC,"Malloc failed in _debug_alloc\n");
pnew->file = strdup(file);
pnew->line = line;
pnew->size = size;
pnew->ptr = ptr;
pnew->next = _debug_memlist.next;
_debug_memlist.next = pnew;
}
void debug_register(char *file, int line, void *ptr, size_t size) {
util_mutex_lock(l_memdebug);
_debug_register_ptr(file, line, ptr, size);
util_mutex_unlock(l_memdebug);
}
void *_debug_alloc(char *file, int line, int size) {
void *ptr;
util_mutex_lock(l_memdebug);
ptr = _debug_alloc_nolock(file, line, size);
util_mutex_unlock(l_memdebug);
return ptr;
}
void debug_dump(void) {
DEBUGNODE *current;
uint32_t size = 0;
int blocks = 0;
if(!_debug_memlist.next) {
DPRINTF(E_LOG,L_MISC,"No leaked memory!\n");
return;
}
current = _debug_memlist.next;
while(current) {
size += current->size;
blocks++;
current = current->next;
}
DPRINTF(E_WARN,L_MISC,"Leaked %d bytes in %d blocks\n",size, blocks);
current = _debug_memlist.next;
while(current) {
DPRINTF(E_WARN,L_MISC,"%d bytes: %s, line %d\n", current->size,
current->file, current->line);
util_hexdump(current->ptr,current->size);
current = current->next;
}
}
void debug_free(char *file, int line, void *ptr) {
DEBUGNODE *prev, *current;
util_mutex_lock(l_memdebug);
prev = &_debug_memlist;
current = prev->next;
while(current) {
if(current->ptr == ptr) {
/* found it */
break;
}
prev = current;
current = current->next;
}
if(!current) {
util_mutex_unlock(l_memdebug);
DPRINTF(E_FATAL,L_MISC,"Attempt to free an unallocated ptr: %s, %d\n",
file, line);
}
prev->next = current->next;
util_mutex_unlock(l_memdebug);
if(current) {
if(current->file)
free(current->file);
if(current->ptr)
free(current->ptr);
free(current);
}
return;
}
void *debug_malloc(char *file, int line, size_t size) {
void *ptr;
ptr = _debug_alloc(file,line,size);
return ptr;
}
void *debug_realloc(char *file, int line, void *ptr, size_t size) {
void *new_ptr;
DEBUGNODE *old_node;
int copy_size;
util_mutex_lock(l_memdebug);
old_node = _debug_find_ptr(ptr);
if(!old_node) {
util_mutex_unlock(l_memdebug);
DPRINTF(E_FATAL,L_MISC,"Attempt to realloc invalid ptr: %s, %d\n",
file, line);
}
new_ptr = _debug_alloc_nolock(file, line, size);
util_mutex_unlock(l_memdebug);
copy_size = old_node->size;
if(size < copy_size)
copy_size=size;
memcpy(new_ptr,old_node->ptr,copy_size);
debug_free(file, line, old_node->ptr);
return new_ptr;
}
void *debug_calloc(char *file, int line, size_t count, size_t size) {
void *ptr;
ptr = debug_malloc(file, line, count * size);
memset(ptr,0,count *size);
return ptr;
}
char *debug_strdup(char *file, int line, const char *str) {
void *ptr;
int size;
size = strlen(str);
ptr = debug_malloc(file, line, size + 1);
strcpy(ptr,str);
return ptr;
}
#endif

View File

@ -1,27 +0,0 @@
/*
* $Id: $
*/
#ifdef DEBUG_MEM
# define free(ptr) debug_free(__FILE__,__LINE__,(ptr))
# define malloc(size) debug_malloc(__FILE__,__LINE__,(size))
# define realloc(ptr, size) debug_realloc(__FILE__,__LINE__,(ptr),(size))
# define calloc(count,size) debug_calloc(__FILE__,__LINE__,(count),(size))
# define strdup(str) debug_strdup(__FILE__,__LINE__,(str))
# define mem_dump() debug_dump()
# define mem_register(ptr, size) debug_register(__FILE__,__LINE__,(ptr),(size))
extern void debug_free(char *file, int line, void *ptr);
extern void *debug_malloc(char *file, int line, size_t size);
extern void *debug_realloc(char *file, int line, void *ptr, size_t size);
extern void *debug_calloc(char *file, int line, size_t count, size_t size);
extern void *debug_strdup(char *file, int line, const char *str);
extern void debug_dump(void);
extern void debug_register(char *file, int line, void *ptr, size_t size);
#else
# define mem_dump();
# define mem_register(ptr, size);
#endif

View File

@ -354,8 +354,6 @@ int scan_mp3_get_mp3tags(char *file, MP3FILE *pmp3) {
utf8_text = (char*)id3_ucs4_utf8duplicate(native_text); utf8_text = (char*)id3_ucs4_utf8duplicate(native_text);
if(utf8_text)
mem_register(utf8_text,0);
if(id3_field_gettextencoding(&pid3frame->fields[1]) == if(id3_field_gettextencoding(&pid3frame->fields[1]) ==
ID3_FIELD_TEXTENCODING_ISO_8859_1) { ID3_FIELD_TEXTENCODING_ISO_8859_1) {
@ -492,8 +490,6 @@ int scan_mp3_get_mp3tags(char *file, MP3FILE *pmp3) {
native_text=id3_field_getstring(&pid3frame->fields[2]); native_text=id3_field_getstring(&pid3frame->fields[2]);
if(native_text) { if(native_text) {
utf8_text=(char*)id3_ucs4_utf8duplicate(native_text); utf8_text=(char*)id3_ucs4_utf8duplicate(native_text);
if(utf8_text)
mem_register(utf8_text,0);
if((utf8_text) && (strncasecmp(utf8_text,"iTun",4) != 0)) { if((utf8_text) && (strncasecmp(utf8_text,"iTun",4) != 0)) {
/* it's a real comment */ /* it's a real comment */
@ -506,7 +502,6 @@ int scan_mp3_get_mp3tags(char *file, MP3FILE *pmp3) {
free(pmp3->comment); free(pmp3->comment);
utf8_text=(char*)id3_ucs4_utf8duplicate(native_text); utf8_text=(char*)id3_ucs4_utf8duplicate(native_text);
if(utf8_text) { if(utf8_text) {
mem_register(utf8_text,0);
pmp3->comment=utf8_text; pmp3->comment=utf8_text;
} }
} }

View File

@ -715,11 +715,3 @@ char *util_vasprintf(char *fmt, va_list ap) {
return outbuf; return outbuf;
} }
#ifdef DEBUG_MEM
void *util_malloc(char *file, char *line, size_t size);
void *util_calloc(char *file, char *line, size_t count, size_t size);
void *util_realloc(char *file, char *line, void *ptr, size_t size);
void util_free(void *ptr);
#endif

View File

@ -21,7 +21,6 @@ typedef enum {
l_err_list, l_err_list,
l_conf, l_conf,
l_plugin, l_plugin,
l_memdebug,
l_upnp, l_upnp,
l_last l_last
} ff_lock_t; } ff_lock_t;