Skip to content

Commit fb5bcc4

Browse files
committed
ess/singleton: use opal_setenv instead of putenv
so it fixes a memory leak on finalize Signed-off-by: Gilles Gouaillardet <[email protected]>
1 parent af67183 commit fb5bcc4

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

orte/mca/ess/singleton/ess_singleton_module.c

Lines changed: 12 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,7 +84,6 @@ static int rte_init(void)
8584
{
8685
int rc, ret;
8786
char *error = NULL;
88-
char *ev1, *ev2;
8987
opal_value_t *kv;
9088
char *val = NULL;
9189
int u32, *u32ptr;
@@ -237,13 +235,17 @@ static int rte_init(void)
237235
* MPI-3 required info key
238236
*/
239237
if (NULL == getenv(OPAL_MCA_PREFIX"orte_ess_num_procs")) {
240-
asprintf(&ev1, OPAL_MCA_PREFIX"orte_ess_num_procs=%d", orte_process_info.num_procs);
241-
putenv(ev1);
238+
char * num_procs;
239+
asprintf(&num_procs, "%d", orte_process_info.num_procs);
240+
opal_setenv(OPAL_MCA_PREFIX"orte_ess_num_procs", num_procs, true, &environ);
241+
free(num_procs);
242242
added_num_procs = true;
243243
}
244244
if (NULL == getenv("OMPI_APP_CTX_NUM_PROCS")) {
245-
asprintf(&ev2, "OMPI_APP_CTX_NUM_PROCS=%d", orte_process_info.num_procs);
246-
putenv(ev2);
245+
char * num_procs;
246+
asprintf(&num_procs, "%d", orte_process_info.num_procs);
247+
opal_setenv("OMPI_APP_CTX_NUM_PROCS", num_procs, true, &environ);
248+
free(num_procs);
247249
added_app_ctx = true;
248250
}
249251

@@ -635,8 +637,10 @@ static int fork_hnp(void)
635637
count = opal_argv_count(argv);
636638
/* push each piece into the environment */
637639
for (i=0; i < count; i++) {
638-
pmixenvars[i] = strdup(argv[i]);
639-
putenv(pmixenvars[i]);
640+
char *c = strchr(argv[i], '=');
641+
assert(NULL != c);
642+
*c++ = '\0';
643+
opal_setenv(argv[i], c, true, &environ);
640644
}
641645
opal_argv_free(argv);
642646
added_pmix_envs = true;

0 commit comments

Comments
 (0)