Module: Mesa
Branch: staging/21.3
Commit: 0353d389fc01d3f8a6ca3e905fa054dbe25e38f9
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=0353d389fc01d3f8a6ca3e905fa054dbe25e38f9

Author: Bas Nieuwenhuizen <[email protected]>
Date:   Sun Jan 23 23:43:49 2022 +0100

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 <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14671>
(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 fbf7ad3e540..d7690747b9e 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -274,7 +274,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);

Reply via email to