From: Timo Sirainen Date: Wed, 20 Jan 2021 18:48:24 +0000 (+0200) Subject: lib: env_put() - Use setenv() instead of putenv() X-Git-Tag: 2.3.16~175 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8e7744b179f58fffa463e720b1786ec9a91a6ddc;p=thirdparty%2Fdovecot%2Fcore.git lib: env_put() - Use setenv() instead of putenv() It's already in POSIX.1-2001 so it should be available everywhere. --- diff --git a/src/lib/env-util.c b/src/lib/env-util.c index 493b9706af..6c12970f43 100644 --- a/src/lib/env-util.c +++ b/src/lib/env-util.c @@ -13,18 +13,12 @@ struct env_backup { const char **strings; }; -static pool_t env_pool = NULL; - void env_put(const char *name, const char *value) { i_assert(strchr(name, '=') == NULL); - if (env_pool == NULL) { - env_pool = pool_alloconly_create(MEMPOOL_GROWING"Environment", - 2048); - } - if (putenv(p_strdup_printf(env_pool, "%s=%s", name, value)) != 0) - i_fatal("putenv(%s=%s) failed: %m", name, value); + if (setenv(name, value, 1) != 0) + i_fatal("setenv(%s, %s) failed: %m", name, value); } void env_put_array(const char *const *envs) @@ -83,8 +77,6 @@ void env_clean(void) */ *environ_p = calloc(1, sizeof(**environ_p)); #endif - if (env_pool != NULL) - p_clear(env_pool); } static void env_clean_except_real(const char *const preserve_envs[]) @@ -167,8 +159,3 @@ char ***env_get_environ_p(void) return &environ; #endif } - -void env_deinit(void) -{ - pool_unref(&env_pool); -} diff --git a/src/lib/env-util.h b/src/lib/env-util.h index 7d3ad5434b..e5b87de029 100644 --- a/src/lib/env-util.h +++ b/src/lib/env-util.h @@ -1,8 +1,10 @@ #ifndef ENV_UTIL_H #define ENV_UTIL_H -/* Add new environment variable. Wrapper to putenv(). Note that calls to this - function allocates memory which isn't free'd until env_clean() is called. */ +/* Add a new environment variable or replace an existing one. + Wrapper to setenv(). Note that setenv() often doesn't free memory used by + replaced environment, so don't keep repeatedly changing values in + environment. */ void env_put(const char *name, const char *value); /* env_put() NULL-terminated array of name=value strings */ void env_put_array(const char *const *envs); @@ -24,8 +26,5 @@ void env_backup_free(struct env_backup **env); directly. */ char ***env_get_environ_p(void); -/* Free all memory used by env_put() function. Environment must not be - accessed afterwards. */ -void env_deinit(void); #endif diff --git a/src/lib/lib.c b/src/lib/lib.c index 5c8853fa98..ab08da66e9 100644 --- a/src/lib/lib.c +++ b/src/lib/lib.c @@ -165,7 +165,6 @@ void lib_deinit(void) restrict_access_deinit(); i_close_fd(&dev_null_fd); data_stack_deinit(); - env_deinit(); failures_deinit(); process_title_deinit(); random_deinit();