Skip to content

Commit e5bf7e5

Browse files
cjatinlamb-j
authored andcommitted
[Comgr] use shared_ptr for rocm path detection
This shows up as a leak. Make sure the memory is released after the program is done executing. Change-Id: I5b3e0a3f0e2e744cb19a9a42be2eb525d5c2bd9d
1 parent 1e0fda7 commit e5bf7e5

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

amd/comgr/src/comgr-env.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "llvm/Support/VirtualFileSystem.h"
3939

4040
#include <fstream>
41+
#include <memory>
4142
#include <stdlib.h>
4243

4344
using namespace llvm;
@@ -245,40 +246,35 @@ class SpackInstallationDetector : public InstallationDetector {
245246
}
246247
};
247248

248-
InstallationDetector *CreatePathDetector(StringRef Path,
249-
bool isComgrPath = false) {
249+
std::shared_ptr<InstallationDetector>
250+
CreatePathDetector(StringRef Path, bool isComgrPath = false) {
250251
StringRef DirName = llvm::sys::path::filename(Path);
251252
if ((!isComgrPath && DirName.starts_with("rocm-cmake-")) ||
252253
(isComgrPath && DirName.starts_with("comgr-"))) {
253-
return new SpackInstallationDetector(Path, isComgrPath);
254+
return std::make_shared<SpackInstallationDetector>(Path, isComgrPath);
254255
}
255256

256-
return new InstallationDetector(Path, isComgrPath);
257+
return std::make_shared<InstallationDetector>(Path, isComgrPath);
257258
}
258259

259-
InstallationDetector *getDetectorImpl() {
260+
std::shared_ptr<InstallationDetector> getDetectorImpl() {
260261
SmallString<128> ROCmInstallPath;
261262

262263
static const char *EnvROCMPath = std::getenv("ROCM_PATH");
263264
if (EnvROCMPath) {
264265
ROCmInstallPath = EnvROCMPath;
265266
}
266267

267-
InstallationDetector *Detector;
268268
if (ROCmInstallPath == "") {
269269
std::string ComgrInstallationPath = getComgrInstallPathFromExecutable();
270-
Detector =
271-
CreatePathDetector(ComgrInstallationPath, true /* isComgrPath */);
272-
} else {
273-
Detector = CreatePathDetector(ROCmInstallPath);
270+
return CreatePathDetector(ComgrInstallationPath, true /* isComgrPath */);
274271
}
275-
276-
return Detector;
272+
return CreatePathDetector(ROCmInstallPath);
277273
}
278274

279275
InstallationDetector *getDetector() {
280-
static InstallationDetector *Detector = getDetectorImpl();
281-
return Detector;
276+
static auto Detector = getDetectorImpl();
277+
return Detector.get();
282278
}
283279

284280
llvm::StringRef getROCMPath() { return getDetector()->getROCmPath(); }

0 commit comments

Comments
 (0)