aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimothy Arceri <tarceri@itsqueeze.com>2017-02-09 22:41:15 +1100
committerTimothy Arceri <tarceri@itsqueeze.com>2017-02-10 09:25:32 +1100
commita4086bb5310984b97054ecec8e3a04780f99d646 (patch)
tree79a5824d17ee81ea7f495d2ba06e6b2e390d5899
parent41ad178b1347ad58a5cbad733426ee3b7b37a835 (diff)
util/disk_cache: error check asprintf()
Fixes: f3d911463e8 "util/disk_cache: stop using ralloc_asprintf() unnecessarily" Reviewed-by: Emil Velikov <emil.velikov@collabora.com> Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
-rw-r--r--src/util/disk_cache.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 885323693bd..c4d08d1ce9e 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -339,7 +339,9 @@ get_cache_file(struct disk_cache *cache, cache_key key)
char *filename;
_mesa_sha1_format(buf, key);
- asprintf(&filename, "%s/%c%c/%s", cache->path, buf[0], buf[1], buf + 2);
+ if (asprintf(&filename, "%s/%c%c/%s", cache->path, buf[0],
+ buf[1], buf + 2) == -1)
+ return NULL;
return filename;
}
@@ -356,9 +358,10 @@ make_cache_file_directory(struct disk_cache *cache, cache_key key)
char buf[41];
_mesa_sha1_format(buf, key);
- asprintf(&dir, "%s/%c%c", cache->path, buf[0], buf[1]);
- mkdir_if_needed(dir);
+ if (asprintf(&dir, "%s/%c%c", cache->path, buf[0], buf[1]) == -1)
+ return;
+ mkdir_if_needed(dir);
free(dir);
}
@@ -577,8 +580,7 @@ disk_cache_put(struct disk_cache *cache,
* final destination filename, (to prevent any readers from seeing
* a partially written file).
*/
- asprintf(&filename_tmp, "%s.tmp", filename);
- if (filename_tmp == NULL)
+ if (asprintf(&filename_tmp, "%s.tmp", filename) == -1)
goto done;
fd = open(filename_tmp, O_WRONLY | O_CLOEXEC | O_CREAT, 0644);