Skip to content

Commit d9b5198

Browse files
Ralph Castainbwbarrett
authored andcommitted
Close the shmemfd to avoid leaking it
Signed-off-by: Ralph Castain <[email protected]> (cherry picked from commit cfa810f)
1 parent 982ed77 commit d9b5198

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

orte/mca/rtc/hwloc/rtc_hwloc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "opal/mca/hwloc/hwloc-internal.h"
3636
#include "opal/mca/pmix/pmix_types.h"
3737
#include "opal/util/argv.h"
38+
#include "opal/util/fd.h"
3839
#include "opal/util/opal_environ.h"
3940
#include "opal/util/path.h"
4041

@@ -168,6 +169,8 @@ static int init(void)
168169
shmemfile = NULL;
169170
return ORTE_SUCCESS;
170171
}
172+
/* ensure nobody inherits this fd */
173+
opal_fd_set_cloexec(shmemfd);
171174
/* populate the shmem segment with the topology */
172175
if (0 != (rc = hwloc_shmem_topology_write(opal_hwloc_topology, shmemfd, 0,
173176
(void*)shmemaddr, shmemsize, 0))) {
@@ -177,6 +180,8 @@ static int init(void)
177180
unlink(shmemfile);
178181
free(shmemfile);
179182
shmemfile = NULL;
183+
close(shmemfd);
184+
shmemfd = -1;
180185
return ORTE_SUCCESS;
181186
}
182187
#endif
@@ -191,6 +196,9 @@ static void finalize(void)
191196
unlink(shmemfile);
192197
free(shmemfile);
193198
}
199+
if (0 <= shmemfd) {
200+
close(shmemfd);
201+
}
194202
#endif
195203
return;
196204
}

0 commit comments

Comments
 (0)