Skip to content

Commit 1a6c17e

Browse files
committed
opal/util: plug a memory leak
by using opal_setenv() instead of putenv() Signed-off-by: Gilles Gouaillardet <[email protected]>
1 parent d0629f1 commit 1a6c17e

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

opal/util/cmd_line.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Copyright (c) 2012-2016 Los Alamos National Security, LLC. All rights
1414
* reserved.
1515
* Copyright (c) 2012-2015 Cisco Systems, Inc. All rights reserved.
16-
* Copyright (c) 2015 Research Organization for Information Science
16+
* Copyright (c) 2015-2017 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
1818
* Copyright (c) 2016 Intel, Inc. All rights reserved
1919
* $COPYRIGHT$
@@ -35,6 +35,7 @@
3535
#include "opal/util/argv.h"
3636
#include "opal/util/cmd_line.h"
3737
#include "opal/util/output.h"
38+
#include "opal/util/opal_environ.h"
3839

3940
#include "opal/mca/base/mca_base_var.h"
4041
#include "opal/constants.h"
@@ -1158,7 +1159,6 @@ static int set_dest(cmd_line_option_t *option, char *sval)
11581159
{
11591160
int ival = atol(sval);
11601161
long lval = strtoul(sval, NULL, 10);
1161-
char *str = NULL;
11621162
size_t i;
11631163

11641164
/* Set MCA param. We do this in the environment because the MCA
@@ -1176,17 +1176,14 @@ static int set_dest(cmd_line_option_t *option, char *sval)
11761176
case OPAL_CMD_LINE_TYPE_STRING:
11771177
case OPAL_CMD_LINE_TYPE_INT:
11781178
case OPAL_CMD_LINE_TYPE_SIZE_T:
1179-
asprintf(&str, "%s=%s", option->clo_mca_param_env_var, sval);
1179+
opal_setenv(option->clo_mca_param_env_var, sval, true, &environ);
11801180
break;
11811181
case OPAL_CMD_LINE_TYPE_BOOL:
1182-
asprintf(&str, "%s=1", option->clo_mca_param_env_var);
1182+
opal_setenv(option->clo_mca_param_env_var, "1", true, &environ);
11831183
break;
11841184
default:
11851185
break;
11861186
}
1187-
if (NULL != str) {
1188-
putenv(str);
1189-
}
11901187
}
11911188

11921189
/* Set variable */

0 commit comments

Comments
 (0)