From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9604 Path: news.gmane.org!not-for-mail From: Alexander Monakov Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH 3/3] env: free allocations in clearenv Date: Sun, 13 Mar 2016 21:53:50 +0300 Message-ID: <1457895230-13602-4-git-send-email-amonakov@ispras.ru> References: <1457895230-13602-1-git-send-email-amonakov@ispras.ru> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1457895266 28208 80.91.229.3 (13 Mar 2016 18:54:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 13 Mar 2016 18:54:26 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-9616-gllmg-musl=m.gmane.org@lists.openwall.com Sun Mar 13 19:54:26 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1afB9k-0001VH-2c for gllmg-musl@m.gmane.org; Sun, 13 Mar 2016 19:54:24 +0100 Original-Received: (qmail 21586 invoked by uid 550); 13 Mar 2016 18:54:15 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 20444 invoked from network); 13 Mar 2016 18:54:01 -0000 X-Mailer: git-send-email 2.1.3 In-Reply-To: <1457895230-13602-1-git-send-email-amonakov@ispras.ru> Xref: news.gmane.org gmane.linux.lib.musl.general:9604 Archived-At: This aligns clearenv with the Linux man page by setting 'environ' rather than '*environ' to NULL, and stops it from leaking entries allocated by the libc. --- src/env/clearenv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/env/clearenv.c b/src/env/clearenv.c index 62d5095..5c16063 100644 --- a/src/env/clearenv.c +++ b/src/env/clearenv.c @@ -1,10 +1,14 @@ #define _GNU_SOURCE #include +#include "libc.h" -extern char **__environ; +static void dummy(char *p, char *r) {} +weak_alias(dummy, __env_change); int clearenv() { - __environ[0] = 0; + char **e = __environ; + __environ = 0; + if (e) while (*e) __env_change(*e++, 0); return 0; } -- 2.1.3