aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Ransom <rransom.8774@gmail.com>2012-02-15 14:09:53 -0800
committerNick Mathewson <nickm@torproject.org>2012-02-17 11:42:21 -0500
commit33552c16ca3644e2dddd8ba6beee58aabd9d1977 (patch)
treefa08a6b3dbf508f520902e22dbef62da6ef74746 /src
parentc0808b795f9b52184a18e7a2960f56ed0e330c4b (diff)
downloadtor-33552c16ca3644e2dddd8ba6beee58aabd9d1977.tar
tor-33552c16ca3644e2dddd8ba6beee58aabd9d1977.tar.gz
Heap-allocate strings returned by get_current_process_environment_variables
Diffstat (limited to 'src')
-rw-r--r--src/common/util.c6
-rw-r--r--src/or/transports.c20
2 files changed, 14 insertions, 12 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 90ad8c09c..509477ad8 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -3832,8 +3832,8 @@ process_environment_make(struct smartlist_t *env_vars)
* process can put strings not of that form in our environment;
* callers should try to not get crashed by that.
*
- * The returned strings are statically allocated, and must be treated
- * as read-only. */
+ * The returned strings are heap-allocated, and must be freed by the
+ * caller. */
struct smartlist_t *
get_current_process_environment_variables(void)
{
@@ -3841,7 +3841,7 @@ get_current_process_environment_variables(void)
char **environ_tmp; /* Not const char ** ? Really? */
for (environ_tmp = environ; *environ_tmp; ++environ_tmp) {
- smartlist_add(sl, (void *)(*environ_tmp));
+ smartlist_add(sl, tor_strdup(*environ_tmp));
}
return sl;
diff --git a/src/or/transports.c b/src/or/transports.c
index c10490e26..726419ed8 100644
--- a/src/or/transports.c
+++ b/src/or/transports.c
@@ -961,13 +961,14 @@ create_managed_proxy_environment(const managed_proxy_t *mp)
{
const or_options_t *options = get_options();
- /* Environment variables to be added to or set in mp's environment.
- * These are heap-allocated and are freed before this function
- * returns. */
+ /* Environment variables to be added to or set in mp's environment. */
smartlist_t *envs = smartlist_new();
+ /* XXXX The next time someone touches this code, shorten the name of
+ * set_environment_variable_in_smartlist, add a
+ * set_env_var_in_smartlist_asprintf function, and get rid of the
+ * silly extra envs smartlist. */
- /* The final environment to be passed to mp. Inherited variables are
- * statically allocated; new ones are heap-allocated. */
+ /* The final environment to be passed to mp. */
smartlist_t *merged_env_vars = get_current_process_environment_variables();
process_environment_t *env;
@@ -1013,16 +1014,17 @@ create_managed_proxy_environment(const managed_proxy_t *mp)
}
SMARTLIST_FOREACH_BEGIN(envs, const char *, env_var) {
- set_environment_variable_in_smartlist(merged_env_vars, env_var, NULL, 0);
+ set_environment_variable_in_smartlist(merged_env_vars, env_var,
+ _tor_free, 1);
} SMARTLIST_FOREACH_END(env_var);
env = process_environment_make(merged_env_vars);
- smartlist_free(merged_env_vars);
-
- SMARTLIST_FOREACH(envs, void *, x, tor_free(x));
smartlist_free(envs);
+ SMARTLIST_FOREACH(merged_env_vars, void *, x, tor_free(x));
+ smartlist_free(merged_env_vars);
+
return env;
}