Mesa (staging/19.1): util/os_file: resize buffer to what was actually needed
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Jun 21 07:41:47 UTC 2019
Module: Mesa
Branch: staging/19.1
Commit: ebd90fc7e00b50ec1d153aa6b0be3482a3f4d662
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=ebd90fc7e00b50ec1d153aa6b0be3482a3f4d662
Author: Eric Engestrom <eric.engestrom at intel.com>
Date: Wed May 1 11:51:01 2019 +0100
util/os_file: resize buffer to what was actually needed
Fixes: 316964709e21286c2af5 "util: add os_read_file() helper"
Reported-by: Jason Ekstrand <jason at jlekstrand.net>
Signed-off-by: Eric Engestrom <eric.engestrom at intel.com>
Reviewed-by: Tapani Pälli <tapani.palli at intel.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
(cherry picked from commit 955c63d3643f30d7db0c5d16e06a5eda4f62f889)
---
src/util/os_file.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/util/os_file.c b/src/util/os_file.c
index da17d12b50e..18727d1121f 100644
--- a/src/util/os_file.c
+++ b/src/util/os_file.c
@@ -92,6 +92,17 @@ os_read_file(const char *filename)
if (read > 0)
offset += read;
+ /* Final resize to actual size */
+ len = offset + 1;
+ char *newbuf = realloc(buf, len);
+ if (!newbuf) {
+ free(buf);
+ close(fd);
+ errno = -ENOMEM;
+ return NULL;
+ }
+ buf = newbuf;
+
buf[offset] = '\0';
return buf;
More information about the mesa-commit
mailing list