Skip to content

Commit 6298474

Browse files
authored
Merge pull request #2093 from lslusarczyk/memleak-fix
fixed issue #1990, L0 leaks checker counts successful create/destroy only
2 parents 3cd6eae + 4bb6a10 commit 6298474

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

source/adapters/level_zero/adapter.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,11 @@ void globalAdapterOnDemandCleanup() {
188188
}
189189

190190
ur_result_t adapterStateTeardown() {
191-
bool LeakFound = false;
192-
193191
// Print the balance of various create/destroy native calls.
194192
// The idea is to verify if the number of create(+) and destroy(-) calls are
195193
// matched.
196194
if (ZeCallCount && (UrL0LeaksDebug) != 0) {
195+
bool LeakFound = false;
197196
// clang-format off
198197
//
199198
// The format of this table is such that each row accounts for a
@@ -276,11 +275,12 @@ ur_result_t adapterStateTeardown() {
276275
ZeCallCount->clear();
277276
delete ZeCallCount;
278277
ZeCallCount = nullptr;
278+
if (LeakFound)
279+
return UR_RESULT_ERROR_INVALID_MEM_OBJECT;
279280
}
280-
if (LeakFound)
281-
return UR_RESULT_ERROR_INVALID_MEM_OBJECT;
282-
// Due to multiple DLLMain definitions with SYCL, register to cleanup the
283-
// Global Adapter after refcnt is 0
281+
282+
// Due to multiple DLLMain definitions with SYCL, register to cleanup the
283+
// Global Adapter after refcnt is 0
284284
#if defined(_WIN32)
285285
umfTearDown();
286286
std::atexit(globalAdapterOnDemandCleanup);

source/adapters/level_zero/common.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,14 @@ ze_result_t ZeCall::doCall(ze_result_t ZeResult, const char *ZeName,
145145
const char *ZeArgs, bool TraceError) {
146146
logger::debug("ZE ---> {}{}", ZeName, ZeArgs);
147147

148-
if (UrL0LeaksDebug) {
149-
++(*ZeCallCount)[ZeName];
148+
if (ZeResult == ZE_RESULT_SUCCESS) {
149+
if (UrL0LeaksDebug) {
150+
++(*ZeCallCount)[ZeName];
151+
}
152+
return ZE_RESULT_SUCCESS;
150153
}
151154

152-
if (ZeResult && TraceError) {
155+
if (TraceError) {
153156
const char *ErrorString = "Unknown";
154157
zeParseError(ZeResult, ErrorString);
155158
logger::error("Error ({}) in {}", ErrorString, ZeName);

0 commit comments

Comments
 (0)