From 2401f4a91855b2ac78c5bad3e6657913b7124121 Mon Sep 17 00:00:00 2001 From: John Bachan Date: Mon, 3 Oct 2022 17:02:15 -0700 Subject: [PATCH] Fixes a double-free in the error path of ncclCommInitAll. Fixes https://github.com/NVIDIA/nccl/issues/726 --- src/init.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/init.cc b/src/init.cc index 42c1090..8023c49 100644 --- a/src/init.cc +++ b/src/init.cc @@ -1215,6 +1215,7 @@ ncclResult_t ncclCommInitAll(ncclComm_t* comms, int ndev, const int* devlist) { gpuFlags[devlist[i]] = 1; } free(gpuFlags); + gpuFlags = nullptr; } ncclUniqueId uniqueId; @@ -1226,11 +1227,9 @@ ncclResult_t ncclCommInitAll(ncclComm_t* comms, int ndev, const int* devlist) { } NCCLCHECKGOTO(ncclGroupEnd(), ret, fail); -exit: - return ret; fail: - if (gpuFlags) free(gpuFlags); - goto exit; + free(gpuFlags); + return ret; } ncclResult_t ncclCommSetAsyncError(ncclComm_t comm, ncclResult_t nextState) {