Fix memory leak -- not disposing of mp3 struct returned by db_find in main

This commit is contained in:
Ron Pedde 2004-11-13 20:58:30 +00:00
parent 67c6782b3f
commit e24b0b7a66
3 changed files with 15 additions and 9 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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;