Skip to content

Commit 5f4c6eb

Browse files
committed
Remove clear function from RefCountContext
Clear method exposed by RefCountContext class could possibly cause a race condition when misused.
1 parent 0702e7b commit 5f4c6eb

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

scripts/templates/valddi.cpp.mako

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,11 @@ namespace ur_validation_layer
221221
}
222222

223223
${x}_result_t context_t::tearDown() {
224-
${x}_result_t result = ${X}_RESULT_SUCCESS;
225-
226224
if (enableLeakChecking) {
227225
getContext()->refCountContext->logInvalidReferences();
228-
getContext()->refCountContext->clear();
229226
}
230-
return result;
227+
228+
return ${X}_RESULT_SUCCESS;
231229
}
232230

233231
} // namespace ur_validation_layer

source/loader/layers/validation/ur_leak_check.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct RefCountContext {
109109
// No more active adapters, so any references still held are leaked
110110
if (adapterCount == 0) {
111111
logInvalidReferences();
112-
clear();
112+
counts.clear();
113113
}
114114
}
115115

@@ -133,8 +133,6 @@ struct RefCountContext {
133133
updateRefCount(handle, REFCOUNT_CREATE_OR_INCREASE, isAdapterHandle);
134134
}
135135

136-
void clear() { counts.clear(); }
137-
138136
template <typename T> bool isReferenceValid(T handle) {
139137
std::unique_lock<std::mutex> lock(mutex);
140138
auto it = counts.find(static_cast<void *>(handle));

source/loader/layers/validation/ur_valddi.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11182,13 +11182,11 @@ ur_result_t context_t::init(ur_dditable_t *dditable,
1118211182
}
1118311183

1118411184
ur_result_t context_t::tearDown() {
11185-
ur_result_t result = UR_RESULT_SUCCESS;
11186-
1118711185
if (enableLeakChecking) {
1118811186
getContext()->refCountContext->logInvalidReferences();
11189-
getContext()->refCountContext->clear();
1119011187
}
11191-
return result;
11188+
11189+
return UR_RESULT_SUCCESS;
1119211190
}
1119311191

1119411192
} // namespace ur_validation_layer

0 commit comments

Comments
 (0)