mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 15:20:10 +01:00
util/os_file: resize buffer to what was actually needed
Fixes: 316964709e "util: add os_read_file() helper"
Reported-by: Jason Ekstrand <jason@jlekstrand.net>
Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
parent
2743e34f20
commit
955c63d364
1 changed files with 11 additions and 0 deletions
|
|
@ -92,6 +92,17 @@ os_read_file(const char *filename)
|
|||
if (actually_read > 0)
|
||||
offset += actually_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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue