zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Valgrind automatic tests, ran for almost every Zsh test and zredis
Date: Sun, 18 Jun 2017 09:24:18 -0700	[thread overview]
Message-ID: <170618092418.ZM13922@torch.brasslantern.com> (raw)
In-Reply-To: <etPan.59466176.7b5dcfbf.63ea@zdharma.org>

On Jun 18,  1:18pm, Sebastian Gniazdowski wrote:
}
} 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.

Hmm, looking more carefully at this, the problem actually seems to be that
getoutputfile() doesn't need to pass 0 to gettempname() any longer.  There
used to be a direct call to zaddlinknode() in getoutputfile(), which needed
a zalloc() string, but that was replaced by addfilelist() which does its own
internal ztrdup().

So the fix is a whole lot simpler:

diff --git a/Src/exec.c b/Src/exec.c
index debb0ae..0a96879 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4570,7 +4570,7 @@ getoutputfile(char *cmd, char **eptr)
     }
     if (!(prog = parsecmd(cmd, eptr)))
 	return NULL;
-    if (!(nam = gettempname(NULL, 0)))
+    if (!(nam = gettempname(NULL, 1)))
 	return NULL;
 
     if ((s = simple_redir_name(prog, REDIR_HERESTR))) {
@@ -4601,7 +4601,7 @@ getoutputfile(char *cmd, char **eptr)
 	    suffix = dyncat(nam, unmeta(suffix));
 	    if (link(nam, suffix) == 0) {
 		addfilelist(nam, 0);
-		nam = ztrdup(suffix);
+		nam = suffix;
 	    }
 	}
     }


  reply	other threads:[~2017-06-18 16:23 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
2017-06-18 16:24     ` Bart Schaefer [this message]
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=170618092418.ZM13922@torch.brasslantern.com \
    --to=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).