Mesa (master): disk_cache: Fix filename leak on error path.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Sep 17 22:58:57 UTC 2020


Module: Mesa
Branch: master
Commit: 1b862716ddf6de92ba7811edf69e9990783050c7
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1b862716ddf6de92ba7811edf69e9990783050c7

Author: Vinson Lee <vlee at freedesktop.org>
Date:   Tue Sep 15 16:28:06 2020 -0700

disk_cache: Fix filename leak on error path.

Remove filename ralloc comment. filename is allocated by asprintf.

Clean up disk_cache_get dead code left over from 367ac07efcc8
("disk_cache: move cache item loading code into
disk_cache_load_item() helper").

Fix defect reported by Coverity Scan.
Logically dead code (DEADCODE)
dead_error_line: Execution cannot reach this statement:
free(filename);

Signed-off-by: Vinson Lee <vlee at freedesktop.org>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6738>

---

 src/util/disk_cache.c    | 8 +-------
 src/util/disk_cache_os.c | 5 +++--
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 91ef18c4e42..9953de62819 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -372,15 +372,9 @@ disk_cache_get(struct disk_cache *cache, const cache_key key, size_t *size)
 
    char *filename = disk_cache_get_cache_filename(cache, key);
    if (filename == NULL)
-      goto fail;
+      return NULL;
 
    return disk_cache_load_item(cache, filename, size);
-
-fail:
-   if (filename)
-      free(filename);
-
-   return NULL;
 }
 
 void
diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c
index fd49bff6dec..b087cd5401f 100644
--- a/src/util/disk_cache_os.c
+++ b/src/util/disk_cache_os.c
@@ -616,6 +616,8 @@ disk_cache_load_item(struct disk_cache *cache, char *filename, size_t *size)
  fail:
    if (data)
       free(data);
+   if (filename)
+      free(filename);
    if (uncompressed_data)
       free(uncompressed_data);
    if (file_header)
@@ -626,8 +628,7 @@ disk_cache_load_item(struct disk_cache *cache, char *filename, size_t *size)
    return NULL;
 }
 
-/* Return a filename within the cache's directory corresponding to 'key'. The
- * returned filename is ralloced with 'cache' as the parent context.
+/* Return a filename within the cache's directory corresponding to 'key'.
  *
  * Returns NULL if out of memory.
  */



More information about the mesa-commit mailing list