From owner-svn-src-all@freebsd.org Wed Jan 1 12:06:37 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 955811D4E3A; Wed, 1 Jan 2020 12:06:37 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47nqdn3RhNz3NYc; Wed, 1 Jan 2020 12:06:37 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7186723BF; Wed, 1 Jan 2020 12:06:37 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 001C6bdL063738; Wed, 1 Jan 2020 12:06:37 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 001C6boS063737; Wed, 1 Jan 2020 12:06:37 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <202001011206.001C6boS063737@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Wed, 1 Jan 2020 12:06:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356251 - head/bin/sh X-SVN-Group: head X-SVN-Commit-Author: jilles X-SVN-Commit-Paths: head/bin/sh X-SVN-Commit-Revision: 356251 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jan 2020 12:06:37 -0000 Author: jilles Date: Wed Jan 1 12:06:37 2020 New Revision: 356251 URL: https://svnweb.freebsd.org/changeset/base/356251 Log: sh: Fix rare memory leak with SIGINT If getcwd() failed earlier on but later succeeded in the pwd builtin, there was no INTOFF protection between calling savestr() and storing its result. It is quite rare for getcwd() to fail, and rarer for it to succeed later in the same directory. Found via code inspection for changing ckmalloc() and similar to assert INTOFF protection instead of applying it directly (which protects against corrupting malloc's internal state but allows memory leaks or double frees). MFC after: 1 week Modified: head/bin/sh/cd.c Modified: head/bin/sh/cd.c ============================================================================== --- head/bin/sh/cd.c Wed Jan 1 09:22:06 2020 (r356250) +++ head/bin/sh/cd.c Wed Jan 1 12:06:37 2020 (r356251) @@ -376,8 +376,11 @@ getpwd(void) return curdir; p = getpwd2(); - if (p != NULL) + if (p != NULL) { + INTOFF; curdir = savestr(p); + INTON; + } return curdir; }