From: Alexander Monakov <amonakov@ispras.ru>
To: musl@lists.openwall.com
Subject: [PATCH 3/3] env: free allocations in clearenv
Date: Sun, 13 Mar 2016 21:53:50 +0300 [thread overview]
Message-ID: <1457895230-13602-4-git-send-email-amonakov@ispras.ru> (raw)
In-Reply-To: <1457895230-13602-1-git-send-email-amonakov@ispras.ru>
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
prev parent reply other threads:[~2016-03-13 18:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-13 18:53 [PATCH 0/3] env functions overhaul Alexander Monakov
2016-03-13 18:53 ` [PATCH 1/3] overhaul environment functions Alexander Monakov
2016-03-19 16:46 ` Rich Felker
2016-03-19 18:11 ` Alexander Monakov
2016-03-20 0:23 ` Rich Felker
2016-03-20 4:15 ` Alexander Monakov
2016-03-20 19:56 ` Rich Felker
2016-03-20 20:15 ` Alexander Monakov
2016-03-21 12:45 ` Alexander Monakov
2016-03-13 18:53 ` [PATCH 2/3] env: remove duplicates when adding to environment Alexander Monakov
2016-03-13 18:53 ` Alexander Monakov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457895230-13602-4-git-send-email-amonakov@ispras.ru \
--to=amonakov@ispras.ru \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).