From: Alexander Monakov Date: Sun, 3 Sep 2017 19:12:21 +0000 (+0300) Subject: free allocations in clearenv X-Git-Tag: v1.1.17~16 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=cc0dbd5f09337c187156fe8b697245e6ea9263d0;p=oweals%2Fmusl.git 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. --- 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 +#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; }