Skip to content

Commit 1daa80d

Browse files
committed
mtl/psm2: plug a memory leak in ompi_mtl_psm2_component_open()
Signed-off-by: Gilles Gouaillardet <[email protected]>
1 parent b343df4 commit 1daa80d

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

ompi/mca/mtl/psm2/mtl_psm2_component.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* Copyright (c) 2012-2015 Los Alamos National Security, LLC.
1515
* All rights reserved.
1616
* Copyright (c) 2013-2015 Intel, Inc. All rights reserved
17+
* Copyright (c) 2017 Research Organization for Information Science
18+
* and Technology (RIST). All rights reserved.
1719
* $COPYRIGHT$
1820
*
1921
* Additional copyrights may follow
@@ -102,16 +104,24 @@ ompi_mtl_psm2_component_register(void)
102104
static int
103105
ompi_mtl_psm2_component_open(void)
104106
{
107+
int res;
105108
glob_t globbuf;
106109
globbuf.gl_offs = 0;
107110

108111
/* Component available only if Omni-Path hardware is present */
109-
if ((glob("/dev/hfi1_[0-9]", GLOB_DOOFFS, NULL, &globbuf) != 0) &&
110-
(glob("/dev/hfi1_[0-9][0-9]", GLOB_APPEND, NULL, &globbuf) != 0)) {
111-
return OPAL_ERR_NOT_AVAILABLE;
112+
res = glob("/dev/hfi1_[0-9]", GLOB_DOOFFS, NULL, &globbuf);
113+
if (0 == res || GLOB_NOMATCH == res) {
114+
globfree(&globbuf);
115+
}
116+
if (0 != res) {
117+
res = glob("/dev/hfi1_[0-9][0-9]", GLOB_APPEND, NULL, &globbuf);
118+
if (0 == res || GLOB_NOMATCH == res) {
119+
globfree(&globbuf);
120+
}
121+
if (0 != res) {
122+
return OPAL_ERR_NOT_AVAILABLE;
123+
}
112124
}
113-
114-
globfree(&globbuf);
115125

116126
/* Component available only if at least one hfi1 port is ACTIVE */
117127
bool foundOnlineHfi1Port = false;

0 commit comments

Comments
 (0)