From 5a233790c38323afaed5ede000e1ef1234755ad7 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Sun, 6 Dec 2015 18:05:32 +0100 Subject: Reduce the initial buffer size for open_memstream Reduce the initial buffer size for open_memstream (used by vasprintf), as most strings are usually smaller than that. Realloc the buffer after finishing the string to further reduce size. Problem appears in case of UCLIBC_HAS_GLIBC_CUSTOM_STREAMS=y, see http://dev.openwrt.org/ticket/13024 Signed-off-by: Felix Fietkau Signed-off-by: Leonid Lisovskiy Signed-off-by: Waldemar Brodkorb --- libc/stdio/open_memstream.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libc/stdio/open_memstream.c') diff --git a/libc/stdio/open_memstream.c b/libc/stdio/open_memstream.c index 5400fe441..17ef191cb 100644 --- a/libc/stdio/open_memstream.c +++ b/libc/stdio/open_memstream.c @@ -17,6 +17,8 @@ #define COOKIE ((__oms_cookie *) cookie) +#define MEMSTREAM_BUFSIZ 256 + typedef struct { char *buf; size_t len; @@ -134,7 +136,7 @@ FILE *open_memstream(char **bufloc, size_t *sizeloc) register FILE *fp; if ((cookie = malloc(sizeof(__oms_cookie))) != NULL) { - if ((cookie->buf = malloc(cookie->len = BUFSIZ)) == NULL) { + if ((cookie->buf = malloc(cookie->len = MEMSTREAM_BUFSIZ)) == NULL) { goto EXIT_cookie; } *cookie->buf = 0; /* Set nul terminator for buffer. */ -- cgit v1.2.3