Date: Wed, 1 Jan 2020 12:06:37 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356251 - head/bin/sh Message-ID: <202001011206.001C6boS063737@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202001011206.001C6boS063737>