From patchwork Mon Nov 21 21:40:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Bofjall X-Patchwork-Id: 9440133 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 25DFB606DB for ; Mon, 21 Nov 2016 21:48:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 193BE28891 for ; Mon, 21 Nov 2016 21:48:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0DA4B289A5; Mon, 21 Nov 2016 21:48:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 351B228891 for ; Mon, 21 Nov 2016 21:48:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754012AbcKUVst (ORCPT ); Mon, 21 Nov 2016 16:48:49 -0500 Received: from h-85-24-133-13.na.cust.bahnhof.se ([85.24.133.13]:33086 "HELO gazonk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1754248AbcKUVsh (ORCPT ); Mon, 21 Nov 2016 16:48:37 -0500 X-Greylist: delayed 451 seconds by postgrey-1.27 at vger.kernel.org; Mon, 21 Nov 2016 16:48:37 EST Received: (qmail 11713 invoked from network); 21 Nov 2016 21:41:01 -0000 Received: from localhost (127.0.0.1) by localhost with SMTP; 21 Nov 2016 21:41:01 -0000 From: Andreas Bofjall To: dash@vger.kernel.org Cc: Andreas Bofjall Subject: [PATCH] trap: fix memory leak in exitshell() Date: Mon, 21 Nov 2016 22:40:52 +0100 Message-Id: <20161121214052.32428-1-andreas@gazonk.org> X-Mailer: git-send-email 2.10.2 Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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: /*