Skip to content

Commit 679927c

Browse files
ggouaillardetRalph Castain
authored andcommitted
ess/singleton: use opal_setenv instead of putenv
so it fixes a memory leak on finalize Signed-off-by: Gilles Gouaillardet <[email protected]> (cherry picked from commit fb5bcc4)
1 parent 035b4bf commit 679927c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

orte/mca/ess/singleton/ess_singleton_module.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ static bool added_transport_keys=false;
7676
static bool added_num_procs = false;
7777
static bool added_app_ctx = false;
7878
static bool added_pmix_envs = false;
79-
static char *pmixenvars[4];
8079
static bool progress_thread_running = false;
8180

8281
static int fork_hnp(void);
@@ -85,9 +84,9 @@ static int rte_init(void)
8584
{
8685
int rc, ret;
8786
char *error = NULL;
88-
char *envar, *ev1, *ev2;
8987
uint64_t unique_key[2];
9088
char *string_key;
89+
char *ev1, *ev2;
9190
opal_value_t *kv;
9291
char *val;
9392
int u32, *u32ptr;
@@ -227,13 +226,17 @@ static int rte_init(void)
227226
* MPI-3 required info key
228227
*/
229228
if (NULL == getenv(OPAL_MCA_PREFIX"orte_ess_num_procs")) {
230-
asprintf(&ev1, OPAL_MCA_PREFIX"orte_ess_num_procs=%d", orte_process_info.num_procs);
231-
putenv(ev1);
229+
char * num_procs;
230+
asprintf(&num_procs, "%d", orte_process_info.num_procs);
231+
opal_setenv(OPAL_MCA_PREFIX"orte_ess_num_procs", num_procs, true, &environ);
232+
free(num_procs);
232233
added_num_procs = true;
233234
}
234235
if (NULL == getenv("OMPI_APP_CTX_NUM_PROCS")) {
235-
asprintf(&ev2, "OMPI_APP_CTX_NUM_PROCS=%d", orte_process_info.num_procs);
236-
putenv(ev2);
236+
char * num_procs;
237+
asprintf(&num_procs, "%d", orte_process_info.num_procs);
238+
opal_setenv("OMPI_APP_CTX_NUM_PROCS", num_procs, true, &environ);
239+
free(num_procs);
237240
added_app_ctx = true;
238241
}
239242

@@ -619,8 +622,10 @@ static int fork_hnp(void)
619622
count = opal_argv_count(argv);
620623
/* push each piece into the environment */
621624
for (i=0; i < count; i++) {
622-
pmixenvars[i] = strdup(argv[i]);
623-
putenv(pmixenvars[i]);
625+
char *c = strchr(argv[i], '=');
626+
assert(NULL != c);
627+
*c++ = '\0';
628+
opal_setenv(argv[i], c, true, &environ);
624629
}
625630
opal_argv_free(argv);
626631
added_pmix_envs = true;

0 commit comments

Comments
 (0)