From: Peter Krempa <pkrempa@redhat.com>
The bufer resizing algorithm resizes the buffer in increments of the
value of the 'BUFSIZ' macro. On linux it's currently 8k. In case when
the caller wants to retain the buffer for long time with little data
read this creates massive overhead.
Realloc the buffer to actual size before returning it to the user.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
src/util/virfile.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 91d5853481..fbcaf15429 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1523,6 +1523,7 @@ saferead_lim(int fd, size_t max_len, size_t *length)
break;
buf[size] = '\0';
*length = size;
+ VIR_REALLOC_N(buf, size + 1);
return buf;
}
}
--
2.53.0