@@ -39,9 +39,11 @@ SanitizerInterceptor::~SanitizerInterceptor() {
39
39
40
40
m_Quarantine = nullptr ;
41
41
m_MemBufferMap.clear ();
42
- m_AllocationMap.clear ();
43
42
m_KernelMap.clear ();
44
43
m_ContextMap.clear ();
44
+ // AllocationMap need to be cleared after ContextMap because memory leak
45
+ // detection depends on it.
46
+ m_AllocationMap.clear ();
45
47
46
48
for (auto Adapter : m_Adapters) {
47
49
getContext ()->urDdiTable .Global .pfnAdapterRelease (Adapter);
@@ -290,7 +292,7 @@ ur_result_t SanitizerInterceptor::postLaunchKernel(ur_kernel_handle_t Kernel,
290
292
ReportFatalError (AH);
291
293
}
292
294
if (!AH.IsRecover ) {
293
- exit ( 1 );
295
+ exitWithErrors ( );
294
296
}
295
297
}
296
298
}
@@ -616,7 +618,7 @@ ur_result_t SanitizerInterceptor::prepareLaunch(
616
618
ContextInfo->Handle , DeviceInfo->Handle , (uptr)Ptr)) {
617
619
ReportInvalidKernelArgument (Kernel, ArgIndex, (uptr)Ptr,
618
620
ValidateResult, PtrPair.second );
619
- exit ( 1 );
621
+ exitWithErrors ( );
620
622
}
621
623
}
622
624
}
@@ -838,12 +840,14 @@ ContextInfo::~ContextInfo() {
838
840
assert (Result == UR_RESULT_SUCCESS);
839
841
840
842
// check memory leaks
841
- std::vector<AllocationIterator> AllocInfos =
842
- getContext ()->interceptor ->findAllocInfoByContext (Handle);
843
- for (const auto &It : AllocInfos) {
844
- const auto &[_, AI] = *It;
845
- if (!AI->IsReleased ) {
846
- ReportMemoryLeak (AI);
843
+ if (getContext ()->interceptor ->isNormalExit ()) {
844
+ std::vector<AllocationIterator> AllocInfos =
845
+ getContext ()->interceptor ->findAllocInfoByContext (Handle);
846
+ for (const auto &It : AllocInfos) {
847
+ const auto &[_, AI] = *It;
848
+ if (!AI->IsReleased ) {
849
+ ReportMemoryLeak (AI);
850
+ }
847
851
}
848
852
}
849
853
}
0 commit comments