From: Sebastian Gniazdowski <psprint@zdharma.org>
To: Bart Schaefer <schaefer@brasslantern.com>, zsh-workers@zsh.org
Subject: Re: Valgrind automatic tests, ran for almost every Zsh test and zredis
Date: Sun, 18 Jun 2017 13:18:14 +0200 [thread overview]
Message-ID: <etPan.59466176.7b5dcfbf.63ea@zdharma.org> (raw)
In-Reply-To: <170616220824.ZM28272@torch.brasslantern.com>
[-- Attachment #1: Type: text/plain, Size: 1496 bytes --]
On 17 czerwca 2017 at 07:08:24, Bart Schaefer (schaefer@brasslantern.com) wrote:
> On Jun 16, 5:14pm, Sebastian Gniazdowski wrote:
> }
> } ============ The maybe-suspicious reports ============
>
> A few of these look like they're probably the same report reached via
> slightly different script paths. The backtraces aren't very helpful
> without knowing which specific test case set them off.
I've fixed this, before each Valgrind error currently executed test case is shown (attached how it looks like).
> I'm guessing most of these are going to turn out to be from a subshell
> exec'ing or exiting without bothering to clean up allocations done by
> the parent, particularly in the case where the leaked memory is from
> the stdio library (indicating "FILE *bshin" was never fclose()d).
I muted many fork / zfork errors initially.
Today I wanted to catch something. The bicat() usage seems to leak what getoutputfile() returns:
- that function always calls: gettempname(NULL, 0), and the 0 == zalloc() memory
- in stringsubst(), after memcpy(), result of getoutputfile() is unused, free to release
Attached is a patch with fix for this, it removes the Valgrind error. The error (Valgrind stack-trace) is attached in the PNG.
I've added 2 error definitions, A04 is now fully silent:
https://github.com/zdharma/VATS-zsh
Does this maybe prove usability of VATS, and open way to add to upstream?
--
Sebastian Gniazdowski
psprint /at/ zdharma.org
[-- Attachment #2: bicat_error.png --]
[-- Type: image/png, Size: 188769 bytes --]
[-- Attachment #3: bicat.diff.txt --]
[-- Type: text/plain, Size: 1706 bytes --]
commit 47aa822fe16e29ba9c9a698f1ba6c830081ea0b2
Author: Sebastian Gniazdowski <sgniazdowski@gmail.com>
Date: Sun Jun 18 12:57:17 2017 +0200
Fix a leak: stringsubst -> getoutputfile -> gettempname -> bicat
diff --git a/Src/exec.c b/Src/exec.c
index debb0ae..133e667 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4570,6 +4570,7 @@ getoutputfile(char *cmd, char **eptr)
}
if (!(prog = parsecmd(cmd, eptr)))
return NULL;
+ /* 0 - getoutputfile always uses zalloc */
if (!(nam = gettempname(NULL, 0)))
return NULL;
diff --git a/Src/subst.c b/Src/subst.c
index 5b1bf89..c2d3aee 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -162,7 +162,7 @@ static LinkNode
stringsubst(LinkList list, LinkNode node, int pf_flags, int *ret_flags,
int asssub)
{
- int qt;
+ int qt, used_zalloc = 0;
char *str3 = (char *)getdata(node);
char *str = str3, c;
@@ -175,8 +175,12 @@ stringsubst(LinkList list, LinkNode node, int pf_flags, int *ret_flags,
if (c == Inang || c == OutangProc)
subst = getproc(str, &rest); /* <(...) or >(...) */
- else
+ else {
+ /* Will use zalloc (always calls gettempname(NULL, 0)), the 0 -> zalloc */
subst = getoutputfile(str, &rest); /* =(...) */
+ if (subst)
+ used_zalloc = 1;
+ }
if (errflag)
return NULL;
if (!subst)
@@ -193,6 +197,9 @@ stringsubst(LinkList list, LinkNode node, int pf_flags, int *ret_flags,
memcpy(sptr, subst, sublen);
sptr += sublen;
}
+ if (used_zalloc && subst) {
+ zfree(subst, sublen);
+ }
if (restlen)
memcpy(sptr, rest, restlen);
sptr[restlen] = '\0';
next prev parent reply other threads:[~2017-06-18 11:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-16 15:14 Sebastian Gniazdowski
2017-06-17 5:08 ` Bart Schaefer
2017-06-18 11:18 ` Sebastian Gniazdowski [this message]
2017-06-18 16:24 ` Bart Schaefer
2017-06-18 16:44 ` Sebastian Gniazdowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=etPan.59466176.7b5dcfbf.63ea@zdharma.org \
--to=psprint@zdharma.org \
--cc=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).