about summary refs log tree commit diff
path: root/src/stdio/open_wmemstream.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdio/open_wmemstream.c')
-rw-r--r--src/stdio/open_wmemstream.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/stdio/open_wmemstream.c b/src/stdio/open_wmemstream.c
index 7ab2c643..4d90cd97 100644
--- a/src/stdio/open_wmemstream.c
+++ b/src/stdio/open_wmemstream.c
@@ -61,14 +61,21 @@ FILE *open_wmemstream(wchar_t **bufp, size_t *sizep)
 {
 	FILE *f;
 	struct cookie *c;
+	wchar_t *buf;
+
 	if (!(f=malloc(sizeof *f + sizeof *c))) return 0;
+	if (!(buf=malloc(sizeof *buf))) {
+		free(f);
+		return 0;
+	}
 	memset(f, 0, sizeof *f + sizeof *c);
 	f->cookie = c = (void *)(f+1);
 
 	c->bufp = bufp;
 	c->sizep = sizep;
-	c->pos = c->len = c->space = 0;
-	c->buf = 0;
+	c->pos = c->len = c->space = *sizep = 0;
+	c->buf = *bufp = buf;
+	*buf = 0;
 
 	f->flags = F_NORD;
 	f->fd = -1;