Skip to content

Commit 062479a

Browse files
committed
minor fixes
1 parent 754ee87 commit 062479a

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

source/loader/layers/sanitizer/asan_interceptor.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,25 +215,28 @@ ur_result_t SanitizerInterceptor::releaseMemory(ur_context_handle_t Context,
215215
if (ReleaseList.size()) {
216216
std::scoped_lock<ur_shared_mutex> Guard(m_AllocationMapMutex);
217217
for (auto &It : ReleaseList) {
218+
auto ToFreeAllocInfo = It->second;
218219
getContext()->logger.info("Quarantine Free: {}",
219-
(void *)It->second->AllocBegin);
220+
(void *)ToFreeAllocInfo->AllocBegin);
220221

221-
ContextInfo->Stats.UpdateUSMRealFreed(AllocInfo->AllocSize,
222-
AllocInfo->getRedzoneSize());
222+
ContextInfo->Stats.UpdateUSMRealFreed(
223+
ToFreeAllocInfo->AllocSize, ToFreeAllocInfo->getRedzoneSize());
223224

224-
m_AllocationMap.erase(It);
225-
if (AllocInfo->Type == AllocType::HOST_USM) {
225+
if (ToFreeAllocInfo->Type == AllocType::HOST_USM) {
226226
for (auto &Device : ContextInfo->DeviceList) {
227227
UR_CALL(getDeviceInfo(Device)->Shadow->ReleaseShadow(
228-
AllocInfo));
228+
ToFreeAllocInfo));
229229
}
230230
} else {
231-
UR_CALL(getDeviceInfo(AllocInfo->Device)
232-
->Shadow->ReleaseShadow(AllocInfo));
231+
UR_CALL(getDeviceInfo(ToFreeAllocInfo->Device)
232+
->Shadow->ReleaseShadow(ToFreeAllocInfo));
233233
}
234234

235235
UR_CALL(getContext()->urDdiTable.USM.pfnFree(
236-
Context, (void *)(It->second->AllocBegin)));
236+
Context, (void *)(ToFreeAllocInfo->AllocBegin)));
237+
238+
// Erase it at last to avoid use-after-free.
239+
m_AllocationMap.erase(It);
237240
}
238241
}
239242
ContextInfo->Stats.UpdateUSMFreed(AllocInfo->AllocSize);

source/loader/layers/sanitizer/asan_shadow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ ur_result_t ShadowMemoryGPU::ReleaseShadow(std::shared_ptr<AllocInfo> AI) {
249249
getContext()->logger.debug("urVirtualMemUnmap: {} ~ {}",
250250
(void *)MappedPtr,
251251
(void *)(MappedPtr + PageSize - 1));
252+
VirtualMemMaps.erase(MappedPtr);
252253
}
253254
}
254255

source/loader/layers/sanitizer/ur_sanddi.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ __urdlllocal ur_result_t UR_APICALL urProgramLink(
357357

358358
UR_CALL(pfnProgramLink(hContext, count, phPrograms, pOptions, phProgram));
359359

360+
UR_CALL(getContext()->interceptor->insertProgram(*phProgram));
360361
UR_CALL(getContext()->interceptor->registerProgram(hContext, *phProgram));
361362

362363
return UR_RESULT_SUCCESS;
@@ -388,6 +389,7 @@ ur_result_t UR_APICALL urProgramLinkExp(
388389
UR_CALL(pfnProgramLinkExp(hContext, numDevices, phDevices, count,
389390
phPrograms, pOptions, phProgram));
390391

392+
UR_CALL(getContext()->interceptor->insertProgram(*phProgram));
391393
UR_CALL(getContext()->interceptor->registerProgram(hContext, *phProgram));
392394

393395
return UR_RESULT_SUCCESS;

0 commit comments

Comments
 (0)