Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Fix leak on print -zf/-sf error
- X-seq: zsh-workers 34490
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: Fix leak on print -zf/-sf error
- Date: Tue, 10 Feb 2015 08:12:36 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=2Im6KHann1YnbEtGQ/BQoNSjDleG12TKunx1fwXot8g=; b=ZsfcuSUmOt0MSqL8eiF7H7bwPKYSHqm+tvuLs4FveXKKpeDq7H7Jl2wHxRpfU7Kelw YacexIgo9UVpLM/sYvoFI6SMdt2zrDsshYoBd8OqROeYuP1ud1asoeCMRL6YFGzusGUb QoT5GATIVD9LHpnVjkdcm/lp5rLpIagFDG9n+1Dw7ACTtMVmB7IlYEj+/qpO6njoXqDj SJnkMMqIvXAxtEQw+6BqEswmW9O0g0C92Qz6PUwh5DqC7u7jOjTaDYh/FPWUguRLIZrf xtqHbv2DwoqqUMRcC8bXjxLX/oAvIfmBgZ5+cuVQOlbB57vhm06wfJa4zzTI0J+zpkMI TVeA==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
for ((i=0; i < 1000000; i++ )); do print -zf hi%\*3\$; done
without the patch, this slowly grows in size, with the patch it doesn't.
---
Src/builtin.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/Src/builtin.c b/Src/builtin.c
index e0f6a5c..eb63657 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3731,7 +3731,7 @@ bin_print(char *name, char **args, Options ops, int func)
int flen, width, prec, type, argc, n, narg, curlen = 0;
int nnl = 0, fmttrunc = 0, ret = 0, maxarg = 0, nc = 0;
int flags[5], *len;
- char *start, *endptr, *c, *d, *flag, *buf, spec[13], *fmt = NULL;
+ char *start, *endptr, *c, *d, *flag, *buf = NULL, spec[13], *fmt = NULL;
char **first, **argp, *curarg, *flagch = "0+- #", save = '\0', nullstr = '\0';
size_t rcount, count = 0;
#ifdef HAVE_OPEN_MEMSTREAM
@@ -4213,6 +4213,10 @@ bin_print(char *name, char **args, Options ops, int func)
narg);
if (fout != stdout)
fclose(fout);
+#ifdef HAVE_OPEN_MEMSTREAM
+ if (buf)
+ free(buf);
+#endif
return 1;
} else {
if (narg > maxarg) maxarg = narg;
@@ -4246,6 +4250,10 @@ bin_print(char *name, char **args, Options ops, int func)
narg);
if (fout != stdout)
fclose(fout);
+#ifdef HAVE_OPEN_MEMSTREAM
+ if (buf)
+ free(buf);
+#endif
return 1;
} else {
if (narg > maxarg) maxarg = narg;
@@ -4275,6 +4283,10 @@ bin_print(char *name, char **args, Options ops, int func)
narg);
if (fout != stdout)
fclose(fout);
+#ifdef HAVE_OPEN_MEMSTREAM
+ if (buf)
+ free(buf);
+#endif
return 1;
} else {
if (narg > maxarg) maxarg = narg;
@@ -4430,6 +4442,10 @@ bin_print(char *name, char **args, Options ops, int func)
(fflush(fout) != 0 && errno != EBADF)) {
zwarnnam(name, "write error: %e", errno);
}
+#ifdef HAVE_OPEN_MEMSTREAM
+ if (buf)
+ free(buf);
+#endif
return 1;
}
--
2.2.0.GIT
Messages sorted by:
Reverse Date,
Date,
Thread,
Author