From 5a233790c38323afaed5ede000e1ef1234755ad7 Mon Sep 17 00:00:00 2001
From: Waldemar Brodkorb <wbx@openadk.org>
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 <nbd@openwrt.org>
Signed-off-by: Leonid Lisovskiy <lly.dev@gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
---
 test/malloc/tst-asprintf.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 test/malloc/tst-asprintf.c

(limited to 'test')

diff --git a/test/malloc/tst-asprintf.c b/test/malloc/tst-asprintf.c
new file mode 100644
index 000000000..d4c3f7676
--- /dev/null
+++ b/test/malloc/tst-asprintf.c
@@ -0,0 +1,27 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <malloc.h>
+
+static void my_stats(void)
+{
+	malloc_stats();
+	fprintf(stderr, "\n");
+}
+
+int main(int argc, char *argv[])
+{
+	char *a, *b;
+
+	my_stats();
+	asprintf(&b, "asdsadasd %ssdf\n", "AAAA");
+	my_stats();
+	asprintf(&a, "asdsadasd %ssdf\n", "AAAA");
+	my_stats();
+	free(a);
+	free(b);
+	my_stats();
+
+	return 0;
+}
-- 
cgit v1.2.3