From 681de726dfc2163f21261b4abd43503e06ae3302 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Wed, 18 Nov 2020 22:05:15 +1030 Subject: [PATCH] Fixed some memory leaks. --- dbindex.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) 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); -- 2.39.5