mirror of
https://github.com/libvirt/libvirt.git
synced 2026-10-02 12:20:06 -05:00
util: file: Shrink buffer returned from 'saferead_lim' to actual size
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> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
1 parent
74b24ffc24
commit
458c6a2810
1 file changed
+1
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user