Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions source/loader/layers/sanitizer/asan_interceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,13 +837,15 @@ ContextInfo::~ContextInfo() {
getContext()->urDdiTable.Context.pfnRelease(Handle);
assert(Result == UR_RESULT_SUCCESS);

// check memory leaks
std::vector<AllocationIterator> AllocInfos =
getContext()->interceptor->findAllocInfoByContext(Handle);
for (const auto &It : AllocInfos) {
const auto &[_, AI] = *It;
if (!AI->IsReleased) {
ReportMemoryLeak(AI);
if (getContext()->interceptor->getOptions().DetectLeaks) {
// check memory leaks
std::vector<AllocationIterator> AllocInfos =
getContext()->interceptor->findAllocInfoByContext(Handle);
for (const auto &It : AllocInfos) {
const auto &[_, AI] = *It;
if (!AI->IsReleased) {
ReportMemoryLeak(AI);
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/loader/layers/sanitizer/asan_interceptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ class SanitizerInterceptor {
std::shared_ptr<DeviceInfo> &DeviceInfo);

private:
// m_Options may be used in other places, place it at the top
AsanOptions m_Options;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a needed change because we need to make sure AsanOptions destucts after ContextInfo so that we can use it in the ~ContextInfo().

std::unordered_map<ur_context_handle_t, std::shared_ptr<ContextInfo>>
m_ContextMap;
ur_shared_mutex m_ContextMapMutex;
Expand All @@ -316,8 +318,6 @@ class SanitizerInterceptor {

std::unique_ptr<Quarantine> m_Quarantine;

AsanOptions m_Options;

std::unordered_set<ur_adapter_handle_t> m_Adapters;
ur_shared_mutex m_AdaptersMutex;
};
Expand Down
1 change: 1 addition & 0 deletions source/loader/layers/sanitizer/asan_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ AsanOptions::AsanOptions() {
SetBoolOption("detect_locals", DetectLocals);
SetBoolOption("detect_privates", DetectPrivates);
SetBoolOption("print_stats", PrintStats);
SetBoolOption("detect_leaks", DetectLeaks);

auto KV = OptionsEnvMap->find("quarantine_size_mb");
if (KV != OptionsEnvMap->end()) {
Expand Down
1 change: 1 addition & 0 deletions source/loader/layers/sanitizer/asan_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct AsanOptions {
bool DetectPrivates = true;
bool PrintStats = false;
bool DetectKernelArguments = true;
bool DetectLeaks = true;

explicit AsanOptions();
};
Expand Down
Loading