fix gigantic memory leak on db enum

This commit is contained in:
Ron Pedde 2004-11-14 06:45:13 +00:00
parent d87940edad
commit 6c1f12ab61

View File

@ -133,16 +133,18 @@ typedef struct {
/* /*
* Globals * Globals
*/ */
int db_version_no; static int db_version_no; /**< db version, incremented every time add or delete */
int db_update_mode=0; static int db_update_mode=0; /**< Are we in the middle of a bulk update? */
int db_song_count; static int db_song_count; /**< Number of songs in the db */
int db_playlist_count=0; static int db_playlist_count=0; /**< Number of active playlists */
int db_last_scan; static int db_last_scan; /**< Dunno... */
DB_PLAYLIST db_playlists; static DB_PLAYLIST db_playlists; /**< The current playlists */
pthread_rwlock_t db_rwlock; /* OSX doesn't have PTHREAD_RWLOCK_INITIALIZER (?!?!?!?!) */ static pthread_rwlock_t db_rwlock; /**< pthread r/w sync for the database */
pthread_once_t db_initlock=PTHREAD_ONCE_INIT; static pthread_once_t db_initlock=PTHREAD_ONCE_INIT; /**< to initialize the rwlock */
GDBM_FILE db_songs; static GDBM_FILE db_songs; /**< Database that holds the mp3 info */
struct rbtree *db_removed; static struct rbtree *db_removed; /**< rbtree to do quick searchs to do background scans */
static MP3FILE gdbm_mp3; /**< used during enumerations */
static int gdbm_mustfree=0; /**< is the data in #gdbm_mp3 valid? Should it be freed? */
/* /*
* Forwards * Forwards
@ -985,6 +987,11 @@ ENUMHANDLE db_enum_begin(void) {
db_writelock(); db_writelock();
if(gdbm_mp3_mustfree) {
db_dispose(gdbm_mp3);
}
gdbm_mp3_mustfree=0;
*pkey=gdbm_firstkey(db_songs); *pkey=gdbm_firstkey(db_songs);
return (ENUMHANDLE)pkey; return (ENUMHANDLE)pkey;
} }
@ -993,7 +1000,11 @@ MP3FILE *db_enum(ENUMHANDLE *current) {
datum *pkey = *current; datum *pkey = *current;
datum next; datum next;
datum data; datum data;
static MP3FILE mp3;
if(gdbm_mp3_mustfree) {
db_dispose(gdbm_mp3);
}
gdbm_mp3_mustfree=0;
if(pkey->dptr) { if(pkey->dptr) {
data=gdbm_fetch(db_songs,*pkey); data=gdbm_fetch(db_songs,*pkey);
@ -1018,6 +1029,11 @@ MP3FILE *db_enum(ENUMHANDLE *current) {
int db_enum_end(ENUMHANDLE handle) { int db_enum_end(ENUMHANDLE handle) {
datum *pkey = handle; datum *pkey = handle;
if(gdbm_mp3_mustfree) {
db_dispose(gdbm_mp3);
}
gdbm_mp3_mustfree=0;
if(pkey->dptr) if(pkey->dptr)
free(pkey->dptr); free(pkey->dptr);