util/disk_cache: error check asprintf()
Fixes: f3d911463e
"util/disk_cache: stop using ralloc_asprintf() unnecessarily"
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
This commit is contained in:
@@ -339,7 +339,9 @@ get_cache_file(struct disk_cache *cache, cache_key key)
|
|||||||
char *filename;
|
char *filename;
|
||||||
|
|
||||||
_mesa_sha1_format(buf, key);
|
_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;
|
return filename;
|
||||||
}
|
}
|
||||||
@@ -356,9 +358,10 @@ make_cache_file_directory(struct disk_cache *cache, cache_key key)
|
|||||||
char buf[41];
|
char buf[41];
|
||||||
|
|
||||||
_mesa_sha1_format(buf, key);
|
_mesa_sha1_format(buf, key);
|
||||||
asprintf(&dir, "%s/%c%c", cache->path, buf[0], buf[1]);
|
if (asprintf(&dir, "%s/%c%c", cache->path, buf[0], buf[1]) == -1)
|
||||||
mkdir_if_needed(dir);
|
return;
|
||||||
|
|
||||||
|
mkdir_if_needed(dir);
|
||||||
free(dir);
|
free(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -577,8 +580,7 @@ disk_cache_put(struct disk_cache *cache,
|
|||||||
* final destination filename, (to prevent any readers from seeing
|
* final destination filename, (to prevent any readers from seeing
|
||||||
* a partially written file).
|
* a partially written file).
|
||||||
*/
|
*/
|
||||||
asprintf(&filename_tmp, "%s.tmp", filename);
|
if (asprintf(&filename_tmp, "%s.tmp", filename) == -1)
|
||||||
if (filename_tmp == NULL)
|
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
fd = open(filename_tmp, O_WRONLY | O_CLOEXEC | O_CREAT, 0644);
|
fd = open(filename_tmp, O_WRONLY | O_CLOEXEC | O_CREAT, 0644);
|
||||||
|
Reference in New Issue
Block a user