diff options
author | Felix Fietkau <nbd@openwrt.org> | 2014-05-17 17:36:08 +0000 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2014-05-17 17:36:08 +0000 |
commit | 171211c29faf7f7755a4e4f70cb700588e8011db (patch) | |
tree | 4c3e6e1256c29d78c389cfb5381398256c3faefd /toolchain | |
parent | bb240b50b6d113f399dc34c0fb6ee9599aff6b41 (diff) | |
download | upstream-171211c29faf7f7755a4e4f70cb700588e8011db.tar.gz upstream-171211c29faf7f7755a4e4f70cb700588e8011db.tar.bz2 upstream-171211c29faf7f7755a4e4f70cb700588e8011db.zip |
uClibc: add a patch to reduce vasprintf allocation size (fixes #13024)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
SVN-Revision: 40774
Diffstat (limited to 'toolchain')
-rw-r--r-- | toolchain/uClibc/patches-0.9.33.2/150-vasprintf_size_reduce.patch | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/toolchain/uClibc/patches-0.9.33.2/150-vasprintf_size_reduce.patch b/toolchain/uClibc/patches-0.9.33.2/150-vasprintf_size_reduce.patch new file mode 100644 index 0000000000..7853c1afa0 --- /dev/null +++ b/toolchain/uClibc/patches-0.9.33.2/150-vasprintf_size_reduce.patch @@ -0,0 +1,37 @@ +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. + +Signed-off-by: Felix Fietkau <nbd@openwrt.org> + +--- a/libc/stdio/vasprintf.c ++++ b/libc/stdio/vasprintf.c +@@ -39,6 +39,8 @@ int vasprintf(char **__restrict buf, con + if (rv < 0) { + free(*buf); + *buf = NULL; ++ } else { ++ *buf = realloc(*buf, rv + 1); + } + } + +--- 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 **__restrict b + 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. */ |