From f15d2c8d3a2b37d57fe2f018dd4566bfde9b31bb 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: (cherry picked from commit 51416b1a120e7763ab5cae0dc79031a037023783) --- .pick_status.json | 2 +- src/util/fossilize_db.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index cd09cebbd49..087fb273155 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -931,7 +931,7 @@ "description": "util/fossilize_db: Fix double free in error handling.", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "eca6bb9540d8d1b260511cd0a71bdddb00ff4a3c" }, 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);