Skip to content

Commit ae278fd

Browse files
committed
ompi/runtime: plug a memory leak
declare ompi_mpi_show_mca_params_file as NULL so MPI_T_Init_thread() can be invoked without leaking memory Signed-off-by: Gilles Gouaillardet <[email protected]>
1 parent 43ee08b commit ae278fd

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ompi/runtime/ompi_mpi_params.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* Copyright (c) 2013-2016 Intel, Inc. All rights reserved
1818
* Copyright (c) 2015 Mellanox Technologies, Inc.
1919
* All rights reserved.
20+
* Copyright (c) 2016 Research Organization for Information Science
21+
* and Technology (RIST). All rights reserved.
2022
* $COPYRIGHT$
2123
*
2224
* Additional copyrights may follow
@@ -201,7 +203,6 @@ int ompi_mpi_register_params(void)
201203
}
202204

203205
/* File to use when dumping the parameters */
204-
ompi_mpi_show_mca_params_file = "";
205206
(void) mca_base_var_register("ompi", "mpi", NULL, "show_mca_params_file",
206207
"If mpi_show_mca_params is true, setting this string to a valid filename tells Open MPI to dump all the MCA parameter values into a file suitable for reading via the mca_param_files parameter (good for reproducability of MPI jobs)",
207208
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
@@ -330,7 +331,8 @@ int ompi_show_all_mca_params(int32_t rank, int requested, char *nodename) {
330331
timestamp = time(NULL);
331332

332333
/* Open the file if one is specified */
333-
if (0 != strlen(ompi_mpi_show_mca_params_file)) {
334+
if (NULL != ompi_mpi_show_mca_params_file &&
335+
0 != strlen(ompi_mpi_show_mca_params_file)) {
334336
if ( NULL == (fp = fopen(ompi_mpi_show_mca_params_file, "w")) ) {
335337
opal_output(0, "Unable to open file <%s> to write MCA parameters", ompi_mpi_show_mca_params_file);
336338
return OMPI_ERR_FILE_OPEN_FAILURE;
@@ -389,7 +391,8 @@ int ompi_show_all_mca_params(int32_t rank, int requested, char *nodename) {
389391
}
390392

391393
/* Print the parameter */
392-
if (0 != strlen(ompi_mpi_show_mca_params_file)) {
394+
if (NULL != ompi_mpi_show_mca_params_file &&
395+
0 != strlen(ompi_mpi_show_mca_params_file)) {
393396
fprintf(fp, "%s\n", var_dump[0]);
394397
} else {
395398
opal_output(0, "%s\n", var_dump[0]);
@@ -399,7 +402,8 @@ int ompi_show_all_mca_params(int32_t rank, int requested, char *nodename) {
399402
}
400403

401404
/* Close file, cleanup allocated memory*/
402-
if (0 != strlen(ompi_mpi_show_mca_params_file)) {
405+
if (NULL != ompi_mpi_show_mca_params_file &&
406+
0 != strlen(ompi_mpi_show_mca_params_file)) {
403407
fclose(fp);
404408
}
405409

0 commit comments

Comments
 (0)