From cfa810f1254412fac343d07488c99bd9c4556bb8 Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Wed, 13 Dec 2017 10:18:09 -0800 Subject: [PATCH] Close the shmemfd to avoid leaking it Signed-off-by: Ralph Castain --- orte/mca/rtc/hwloc/rtc_hwloc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/orte/mca/rtc/hwloc/rtc_hwloc.c b/orte/mca/rtc/hwloc/rtc_hwloc.c index f9cbf93609..b832d4cf6b 100644 --- a/orte/mca/rtc/hwloc/rtc_hwloc.c +++ b/orte/mca/rtc/hwloc/rtc_hwloc.c @@ -35,6 +35,7 @@ #include "opal/mca/hwloc/hwloc-internal.h" #include "opal/mca/pmix/pmix_types.h" #include "opal/util/argv.h" +#include "opal/util/fd.h" #include "opal/util/opal_environ.h" #include "opal/util/path.h" @@ -168,6 +169,8 @@ static int init(void) shmemfile = NULL; return ORTE_SUCCESS; } + /* ensure nobody inherits this fd */ + opal_fd_set_cloexec(shmemfd); /* populate the shmem segment with the topology */ if (0 != (rc = hwloc_shmem_topology_write(opal_hwloc_topology, shmemfd, 0, (void*)shmemaddr, shmemsize, 0))) { @@ -177,6 +180,8 @@ static int init(void) unlink(shmemfile); free(shmemfile); shmemfile = NULL; + close(shmemfd); + shmemfd = -1; return ORTE_SUCCESS; } #endif @@ -191,6 +196,9 @@ static void finalize(void) unlink(shmemfile); free(shmemfile); } + if (0 <= shmemfd) { + close(shmemfd); + } #endif return; }