dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Bofjall <andreas@gazonk.org>
To: dash@vger.kernel.org
Cc: Andreas Bofjall <andreas@gazonk.org>
Subject: [PATCH v2] trap: fix memory leak in exitshell()
Date: Thu,  1 Dec 2016 22:17:07 +0100	[thread overview]
Message-ID: <20161201211707.4710-1-andreas@gazonk.org> (raw)

After dash had executed the exit trap handler, the trap was reset but
the pointer was never freed. This leak can be demonstrated by running
dash through valgrind and executing the following shell script:

	foo() {
	trap foo EXIT

Fix by properly freeing the trap pointer in exitshell().

Signed-off-by: Andreas Bofjall <andreas@gazonk.org>
v2: move ckfree() to out path

 src/trap.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/trap.c b/src/trap.c
index edb9938..0824223 100644
--- a/src/trap.c
+++ b/src/trap.c
@@ -378,7 +378,7 @@ void
 	struct jmploc loc;
-	char *p;
+	char *p = NULL;
 	savestatus = exitstatus;
 	TRACE(("pid %d, exitshell(%d)\n", getpid(), savestatus));
@@ -391,6 +391,9 @@ exitshell(void)
 		evalstring(p, 0);
+	ckfree(p);
 	 * Disable job control so that whoever had the foreground before we
 	 * started can get it back.

                 reply	other threads:[~2016-12-01 21:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161201211707.4710-1-andreas@gazonk.org \
    --to=andreas@gazonk.org \
    --cc=dash@vger.kernel.org \
    --subject='Re: [PATCH v2] trap: fix memory leak in exitshell()' \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).