diff --git a/src/util/os_file.c b/src/util/os_file.c index a700f3aada3..756164c3dfe 100644 --- a/src/util/os_file.c +++ b/src/util/os_file.c @@ -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;