Linux-Dash 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] trap: fix memory leak in exitshell()
Date: Mon, 21 Nov 2016 22:40:52 +0100	[thread overview]
Message-ID: <20161121214052.32428-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() {
	    true
	}
	trap foo EXIT

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

Signed-off-by: Andreas Bofjall <andreas@gazonk.org>
---
 src/trap.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/trap.c b/src/trap.c
index edb9938..5418b07 100644
--- a/src/trap.c
+++ b/src/trap.c
@@ -389,6 +389,7 @@ exitshell(void)
 		trap[0] = NULL;
 		evalskip = 0;
 		evalstring(p, 0);
+		ckfree(p);
 	}
 out:
 	/*
-- 
2.10.2


             reply	other threads:[~2016-11-21 21:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-21 21:40 Andreas Bofjall [this message]
2016-11-22 21:51 ` [PATCH] trap: fix memory leak in exitshell() Jilles Tjoelker
2016-11-22 22:47   ` Andreas Bofjäll

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=20161121214052.32428-1-andreas@gazonk.org \
    --to=andreas@gazonk.org \
    --cc=dash@vger.kernel.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).