changeset 19595:d993ed368ee0

lib: Don't crash if getenv() is called after process_title_deinit() with Linux/OSX PROCTITLE_HACK Right now the only known issue is GNUTLS's lib_deinit(): e = getenv("GNUTLS_NO_EXPLICIT_INIT"); But we likely never want that to be set. Alternative ways to solve this are more annoying than our clearing the environment. Libraries probably shouldn't rely on it much anyway, because some parts of Dovecot clear the whole environment while running.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Tue, 19 Jan 2016 20:45:27 +0200
parents 30d1d947b589
children 3e4358b58c3f
files src/lib/process-title.c
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/process-title.c	Tue Jan 19 15:39:13 2016 +0200
+++ b/src/lib/process-title.c	Tue Jan 19 20:45:27 2016 +0200
@@ -147,7 +147,19 @@
 void process_title_deinit(void)
 {
 #ifdef PROCTITLE_HACK
+	char ***environ_p = env_get_environ_p();
+
 	free(argv_memblock);
 	free(environ_memblock);
+
+	/* Environment is no longer usable. Make sure we won't crash in case
+	   some library's deinit function still calls getenv(). This code was
+	   mainly added because of GNUTLS where we don't really care about the
+	   getenv() call.
+
+	   Alternatively we could remove the free() calls above, but that would
+	   annoy memory leak checking tools. Also we could attempt to restore
+	   the environ_p to its original state, but that's a bit complicated. */
+	*environ_p = NULL;
 #endif
 }