Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 13 Mar 2016 21:53:50 +0300
From: Alexander Monakov <amonakov@...ras.ru>
To: musl@...ts.openwall.com
Subject: [PATCH 3/3] env: free allocations in clearenv

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 <stdlib.h>
+#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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.