Skip to content

Commit c18939c

Browse files
Simple fix for potential memory leak.
Change-Id: I3cb96ce810e5cd83fe3ce55182f39c6fc2264629 Signed-off-by: davidoli <[email protected]>
1 parent aa7bd64 commit c18939c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

level_zero/tools/source/pin/pin.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,31 @@ const std::string gtPinOpenFunctionName = "OpenGTPin";
1919
namespace L0 {
2020

2121
void PinContext::init(ze_init_flag_t flag, ze_result_t &result) {
22+
std::unique_ptr<NEO::OsLibrary> hGtPinLibrary = nullptr;
2223
result = ZE_RESULT_SUCCESS;
2324

2425
if (!getenv_tobool("ZE_ENABLE_PROGRAM_INSTRUMENTATION")) {
2526
return;
2627
}
2728

28-
NEO::OsLibrary *hPin = NEO::OsLibrary::load(gtPinLibraryFilename.c_str());
29-
if (hPin == nullptr) {
29+
hGtPinLibrary.reset(NEO::OsLibrary::load(gtPinLibraryFilename.c_str()));
30+
if (hGtPinLibrary.get() == nullptr) {
3031
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Unable to find gtpin library %s\n", gtPinLibraryFilename.c_str());
3132
result = ZE_RESULT_ERROR_UNKNOWN;
3233
return;
3334
}
3435

35-
OpenGTPin_fn openGTPin = reinterpret_cast<OpenGTPin_fn>(hPin->getProcAddress(gtPinOpenFunctionName.c_str()));
36+
OpenGTPin_fn openGTPin = reinterpret_cast<OpenGTPin_fn>(hGtPinLibrary.get()->getProcAddress(gtPinOpenFunctionName.c_str()));
3637
if (openGTPin == nullptr) {
38+
hGtPinLibrary.reset(nullptr);
3739
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Unable to find gtpin library open function symbol %s\n", gtPinOpenFunctionName.c_str());
3840
result = ZE_RESULT_ERROR_UNKNOWN;
3941
return;
4042
}
4143

4244
uint32_t openResult = openGTPin(nullptr);
4345
if (openResult != 0) {
46+
hGtPinLibrary.reset(nullptr);
4447
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "gtpin library open %s failed with status %u\n", gtPinOpenFunctionName.c_str(), openResult);
4548
result = ZE_RESULT_ERROR_UNKNOWN;
4649
return;

0 commit comments

Comments
 (0)