From: Not Zed Date: Wed, 18 Nov 2020 11:35:15 +0000 (+1030) Subject: Fixed some memory leaks. X-Git-Url: https://code.zedzone.au/cvs?a=commitdiff_plain;h=681de726dfc2163f21261b4abd43503e06ae3302;p=playerz Fixed some memory leaks. --- diff --git a/dbindex.c b/dbindex.c index 2cfd282..21313d7 100644 --- a/dbindex.c +++ b/dbindex.c @@ -905,15 +905,21 @@ static int dbfile_iterate_shuffle(dbindex *db, dbfile **fp, char **pathp, int fi /* Scan based on shuffle order */ - int *keyval = *fp ? &((*fp)->id) : NULL; + int keyval = *fp ? ((*fp)->id) : -1; dbdisk *disk = *fp ? dbdisk_get(tx, db, (*fp)->diskid) : NULL; int mounted = *fp ? dbdisk_mounted(disk) : 0; - printf("shuffle next, fid=%d\n", keyval ? *keyval : -1); - if (keyval) { - data.mv_data = keyval; - data.mv_size = sizeof(*keyval); + printf("shuffle next, fid=%d\n", keyval); + + dbfile_free(*fp); + free(*pathp); + *fp = NULL; + *pathp = NULL; + + if (keyval != -1) { + data.mv_data = &keyval; + data.mv_size = sizeof(keyval); res = mdb_get(tx, db->shuffle_by_file, &data, &key); printf("get by file = %d, id=%d\n", res, *((int *)key.mv_data)); @@ -932,17 +938,12 @@ static int dbfile_iterate_shuffle(dbindex *db, dbfile **fp, char **pathp, int fi res = mdb_cursor_get(cursor, &key, &data, first); } - dbfile_free(*fp); - *fp = NULL; - free(*pathp); - *pathp = NULL; - while (file == NULL && res == 0) { file = primary_get_decode(tx, db, DBFILE_DESC, &data, db->file); if (file) { int keep; - printf("loaded: %d[%d] %d?\n", *(int *)data.mv_data, data.mv_size, file->id); + printf("loaded: %d[%zd] %d?\n", *(int *)data.mv_data, data.mv_size, file->id); if (disk == NULL || file->diskid != disk->id) { dbdisk_free(disk);