From 29ca4c8015b4936378d49937f97049f33d3aaaf9 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 19 Jan 2016 20:45:27 +0200 Subject: [PATCH] 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. --- src/lib/process-title.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib/process-title.c b/src/lib/process-title.c index bda21717cd..14d203e8d1 100644 --- a/src/lib/process-title.c +++ b/src/lib/process-title.c @@ -147,7 +147,19 @@ void process_title_set(const char *title ATTR_UNUSED) 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 } -- 2.47.3