From 51416b1a120e7763ab5cae0dc79031a037023783 Mon Sep 17 00:00:00 2001 From: Bas Nieuwenhuizen Date: Sun, 23 Jan 2022 23:43:49 +0100 Subject: [PATCH] util/fossilize_db: Fix double free in error handling. If the file ptr is not NULL then foz_destroy will also try to destroy it. Fixes: eca6bb9540d ("util/fossilize_db: add basic fossilize db util to read/write shader caches") Reviewed-by: Timothy Arceri Part-of: --- src/util/fossilize_db.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util/fossilize_db.c b/src/util/fossilize_db.c index 26024101b83..40164306202 100644 --- a/src/util/fossilize_db.c +++ b/src/util/fossilize_db.c @@ -318,8 +318,12 @@ foz_prepare(struct foz_db *foz_db, char *cache_path) free(filename); free(idx_filename); - if (!check_files_opened_successfully(foz_db->file[file_idx], db_idx)) + if (!check_files_opened_successfully(foz_db->file[file_idx], db_idx)) { + /* Prevent foz_destroy from destroying it a second time. */ + foz_db->file[file_idx] = NULL; + continue; /* Ignore invalid user provided filename and continue */ + } if (!load_foz_dbs(foz_db, db_idx, file_idx, true)) { fclose(db_idx);