dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] trap: fix memory leak in exitshell()
@ 2016-12-01 21:17 Andreas Bofjall
  0 siblings, 0 replies; only message in thread
From: Andreas Bofjall @ 2016-12-01 21:17 UTC (permalink / raw)
  To: dash; +Cc: Andreas Bofjall

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>
---
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
 exitshell(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);
 	}
 out:
+	INTOFF;
+	ckfree(p);
+	INTON;
 	/*
 	 * Disable job control so that whoever had the foreground before we
 	 * started can get it back.
-- 
2.10.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-12-01 21:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-01 21:17 [PATCH v2] trap: fix memory leak in exitshell() Andreas Bofjall

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