@@ -39,9 +39,11 @@ SanitizerInterceptor::~SanitizerInterceptor() {
3939
4040 m_Quarantine = nullptr ;
4141 m_MemBufferMap.clear ();
42- m_AllocationMap.clear ();
4342 m_KernelMap.clear ();
4443 m_ContextMap.clear ();
44+ // AllocationMap need to be cleared after ContextMap because memory leak
45+ // detection depends on it.
46+ m_AllocationMap.clear ();
4547
4648 for (auto Adapter : m_Adapters) {
4749 getContext ()->urDdiTable .Global .pfnAdapterRelease (Adapter);
@@ -290,7 +292,7 @@ ur_result_t SanitizerInterceptor::postLaunchKernel(ur_kernel_handle_t Kernel,
290292 ReportFatalError (AH);
291293 }
292294 if (!AH.IsRecover ) {
293- exit ( 1 );
295+ exitWithErrors ( );
294296 }
295297 }
296298 }
@@ -616,7 +618,7 @@ ur_result_t SanitizerInterceptor::prepareLaunch(
616618 ContextInfo->Handle , DeviceInfo->Handle , (uptr)Ptr)) {
617619 ReportInvalidKernelArgument (Kernel, ArgIndex, (uptr)Ptr,
618620 ValidateResult, PtrPair.second );
619- exit ( 1 );
621+ exitWithErrors ( );
620622 }
621623 }
622624 }
@@ -838,12 +840,14 @@ ContextInfo::~ContextInfo() {
838840 assert (Result == UR_RESULT_SUCCESS);
839841
840842 // 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+ }
847851 }
848852 }
849853}
0 commit comments