about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander Monakov <amonakov@ispras.ru>2017-09-03 22:12:21 +0300
committerRich Felker <dalias@aerifal.cx>2017-09-04 15:55:21 -0400
commitcc0dbd5f09337c187156fe8b697245e6ea9263d0 (patch)
treeacd199bba8ec96d1a5ad250ac7211d1d8346e578 /src
parent8e932792c917d11545c2953b35159149f7411eca (diff)
downloadmusl-cc0dbd5f09337c187156fe8b697245e6ea9263d0.tar.gz
musl-cc0dbd5f09337c187156fe8b697245e6ea9263d0.tar.xz
musl-cc0dbd5f09337c187156fe8b697245e6ea9263d0.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/env/clearenv.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/env/clearenv.c b/src/env/clearenv.c
index 62d50952..da187752 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 *old, char *new) {}
+weak_alias(dummy, __env_rm_add);
 
 int clearenv()
 {
-	__environ[0] = 0;
+	char **e = __environ;
+	__environ = 0;
+	if (e) while (*e) __env_rm_add(*e++, 0);
 	return 0;
 }