From e1a73af0a8c25968e9e4c3bf6ba91bc94b3249af Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 16 Nov 2023 13:27:31 +0000 Subject: [PATCH] [Minor] Preserve old environ on exit --- src/libutil/util.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libutil/util.c b/src/libutil/util.c index 1c644c2cc..aa89e84c8 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -533,10 +533,16 @@ void rspamd_signals_init(struct sigaction *signals, void (*sig_handler)(gint)) static gchar *title_buffer = NULL; static size_t title_buffer_size = 0; static gchar *title_progname, *title_progname_full; +gchar **old_environ = NULL; static void rspamd_title_dtor(gpointer d) { + /* Restore old environment */ + if (old_environ != NULL) { + environ = old_environ; + } + gchar **env = (gchar **) d; guint i; @@ -603,12 +609,14 @@ gint rspamd_init_title(rspamd_mempool_t *pool, program_invocation_short_name = title_progname; } + old_environ = environ; environ = new_environ; title_buffer = begin_of_buffer; title_buffer_size = end_of_buffer - begin_of_buffer; rspamd_mempool_add_destructor(pool, - rspamd_title_dtor, new_environ); + rspamd_title_dtor, + new_environ); #endif return 0; -- 2.39.5