From patchwork Thu Nov 22 13:10:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ron Yorston X-Patchwork-Id: 10694139 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-2.web.codeaurora.org (Postfix) with ESMTP id 379B71926 for ; Thu, 22 Nov 2018 13:10:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E6DF2CA9F for ; Thu, 22 Nov 2018 13:10:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 122EF2CAB0; Thu, 22 Nov 2018 13:10:24 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 8F0872CA9F for ; Thu, 22 Nov 2018 13:10:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727681AbeKVXtj (ORCPT ); Thu, 22 Nov 2018 18:49:39 -0500 Received: from haggis.mythic-beasts.com ([46.235.224.141]:50545 "EHLO haggis.mythic-beasts.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727034AbeKVXtj (ORCPT ); Thu, 22 Nov 2018 18:49:39 -0500 Received: from [2a00:1098:0:86:1000:33:962f:89b6] (port=35124 helo=frippery.frippery.org) by haggis.mythic-beasts.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1gPokO-0001W6-V7; Thu, 22 Nov 2018 13:10:20 +0000 Received: by frippery.frippery.org (Postfix, from userid 1000) id 8DA0520738; Thu, 22 Nov 2018 13:10:20 +0000 (GMT) Date: Thu, 22 Nov 2018 13:10:20 +0000 From: Ron Yorston To: dash@vger.kernel.org Subject: [PATCH] eval: avoid leaking memory associated with redirections Message-ID: <5bf6aabc.5IrNAw91xx5SQEm6%rmy@frippery.org> User-Agent: Heirloom mailx 12.4 7/29/08 MIME-Version: 1.0 Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The following constructs result in ever-increasing memory usage: while true; do { true; } --- src/eval.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/eval.c b/src/eval.c index 546ee1b..9f117ea 100644 --- a/src/eval.c +++ b/src/eval.c @@ -202,6 +202,7 @@ evaltree(union node *n, int flags) int (*evalfn)(union node *, int); unsigned isor; int status = 0; + struct stackmark smark; if (n == NULL) { TRACE(("evaltree(NULL) called\n")); goto out; @@ -227,6 +228,7 @@ evaltree(union node *n, int flags) status = !evaltree(n->nnot.com, EV_TESTED); goto setstatus; case NREDIR: + setstackmark(&smark); errlinno = lineno = n->nredir.linno; if (funcline) lineno -= funcline - 1; @@ -236,6 +238,7 @@ evaltree(union node *n, int flags) evaltree(n->nredir.n, flags & EV_TESTED); if (n->nredir.redirect) popredir(0); + popstackmark(&smark); goto setstatus; case NCMD: #ifdef notyet @@ -476,11 +479,13 @@ evalsubshell(union node *n, int flags) struct job *jp; int backgnd = (n->type == NBACKGND); int status; + struct stackmark smark; errlinno = lineno = n->nredir.linno; if (funcline) lineno -= funcline - 1; + setstackmark(&smark); expredir(n->nredir.redirect); if (!backgnd && flags & EV_EXIT && !have_traps()) goto nofork; @@ -500,6 +505,7 @@ nofork: if (! backgnd) status = waitforjob(jp); INTON; + popstackmark(&smark); return status; }