]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: env_put() - Use setenv() instead of putenv()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 20 Jan 2021 18:48:24 +0000 (20:48 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 10 May 2021 06:30:45 +0000 (09:30 +0300)
It's already in POSIX.1-2001 so it should be available everywhere.

src/lib/env-util.c
src/lib/env-util.h
src/lib/lib.c

index 493b9706af2521c432eae94075482aecedcca22c..6c12970f4365d7b3e2f670d537102ee2b57c010d 100644 (file)
@@ -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);
-}
index 7d3ad5434b423dcaecb997cffc50f130f103d7c2..e5b87de029fb88a36fe8c8c3f60cb502a1b9408b 100644 (file)
@@ -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
index 5c8853fa98b90529a3f64c333d8265e11f9d3fa5..ab08da66e9070866a706d8c0494329a06e38189f 100644 (file)
@@ -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();