From e24b0b7a66a7a1a17602a525c7283ad66fdf42a1 Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Sat, 13 Nov 2004 20:58:30 +0000 Subject: [PATCH] Fix memory leak -- not disposing of mp3 struct returned by db_find in main --- src/db-gdbm.c | 13 ++++++------- src/db-memory.h | 1 + src/main.c | 10 ++++++++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/db-gdbm.c b/src/db-gdbm.c index dc7fb366..62248cc6 100644 --- a/src/db-gdbm.c +++ b/src/db-gdbm.c @@ -171,7 +171,7 @@ char *db_get_playlist_name(int playlistid); MP3FILE *db_find(int id); -void db_freefile(MP3FILE *pmp3); +void db_dispose(MP3FILE *pmp3); int db_compare_rb_nodes(const void *pa, const void *pb, const void *cfg); @@ -290,7 +290,7 @@ int db_init(void) { if(!db_unpackrecord(&song_data,&mp3file)) { /* Check against playlist */ pl_eval(&mp3file); - db_freefile(&mp3file); + db_dispose(&mp3file); } free(song_data.dptr); } @@ -815,11 +815,11 @@ int db_add(MP3FILE *pmp3) { } /* - * db_freefile + * db_dispose * * free a complete mp3record */ -void db_freefile(MP3FILE *pmp3) { +void db_dispose(MP3FILE *pmp3) { MAYBEFREE(pmp3->path); MAYBEFREE(pmp3->fname); MAYBEFREE(pmp3->title); @@ -966,7 +966,7 @@ int db_enum_end(ENUMHANDLE handle) { helper->root = record->next; - db_freefile(&record->mp3file); + db_dispose(&record->mp3file); } free(helper); @@ -1161,7 +1161,6 @@ MP3FILE *db_find(int id) { /* FIXME: Not reentrant */ return pmp3; } - /* * db_get_playlist_count * @@ -1318,7 +1317,7 @@ int db_last_modified(int id) { } if(pmp3) { - db_freefile(pmp3); + db_dispose(pmp3); free(pmp3); } diff --git a/src/db-memory.h b/src/db-memory.h index ad5f438e..8c37f184 100644 --- a/src/db-memory.h +++ b/src/db-memory.h @@ -42,6 +42,7 @@ extern ENUMHANDLE db_enum_begin(void); extern MP3FILE *db_enum(ENUMHANDLE *handle); extern int db_enum_end(ENUMHANDLE handle); extern MP3FILE *db_find(int id); +extern void db_dispose(MP3FILE *pmp3); /* must be called after a db_find */ extern int db_get_song_count(void); extern int db_get_playlist_count(void); diff --git a/src/main.c b/src/main.c index cfa9e897..8163dc32 100644 --- a/src/main.c +++ b/src/main.c @@ -238,7 +238,7 @@ void daap_handler(WS_CONNINFO *pwsc) { * /databases/id/containers, which returns a container * /databases/id/containers/id/items, which returns playlist elements * /databases/id/items/id.mp3, to spool an mp3 - * /databases/id/browse/category + * /databases/id/browse/category */ uri = strdup(pwsc->uri); @@ -264,6 +264,7 @@ void daap_handler(WS_CONNINFO *pwsc) { *last='\0'; item=atoi(first); streaming=1; + DPRINTF(E_DBG,L_DAAP|L_WS,"Streaming request for id %d\n",item); } free(uri); } else if (strncasecmp(last,"items",5)==0) { @@ -349,6 +350,7 @@ void daap_handler(WS_CONNINFO *pwsc) { pmp3=db_find(item); if(!pmp3) { + DPRINTF(E_LOG,L_DAAP|L_WS|L_DB,"Could not find requested item %d\n",item); ws_returnerror(pwsc,404,"File Not Found"); } else { /* got the file, let's open and serve it */ @@ -359,7 +361,8 @@ void daap_handler(WS_CONNINFO *pwsc) { pwsc->threadno,pmp3->path,strerror(errno)); ws_returnerror(pwsc,404,"Not found"); config_set_status(pwsc,session_id,NULL); - + db_dispose(pmp3); + free(pmp3); } else { real_len=lseek(file_fd,0,SEEK_END); lseek(file_fd,0,SEEK_SET); @@ -437,6 +440,8 @@ void daap_handler(WS_CONNINFO *pwsc) { } config_set_status(pwsc,session_id,NULL); r_close(file_fd); + db_dispose(pmp3); + free(pmp3); } } } @@ -688,6 +693,7 @@ int main(int argc, char *argv[]) { usage(argv[0]); exit(-1); } + exit(0); break; case 'f': foreground=1;