# HG changeset patch # User Timo Sirainen # Date 1453229127 -7200 # Node ID d993ed368ee06f348e60aad4917d853139c2bca5 # Parent 30d1d947b589f05649b7ed0d97bf71f24f9b17a7 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. diff -r 30d1d947b589 -r d993ed368ee0 src/lib/process-title.c --- 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 }