Skip to content

Commit be22ba0

Browse files
committed
fix throw exception on free
1 parent 549f8b7 commit be22ba0

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

source/loader/layers/sanitizer/asan/asan_interceptor.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ ur_result_t AsanInterceptor::releaseMemory(ur_context_handle_t Context,
171171
if (!AllocInfoItOp) {
172172
// "Addr" might be a host pointer
173173
ReportBadFree(Addr, GetCurrentBacktrace(), nullptr);
174-
return UR_RESULT_ERROR_INVALID_ARGUMENT;
174+
if (getOptions().HaltOnError) {
175+
exitWithErrors();
176+
}
177+
return UR_RESULT_SUCCESS;
175178
}
176179

177180
auto AllocInfoIt = *AllocInfoItOp;
@@ -186,17 +189,26 @@ ur_result_t AsanInterceptor::releaseMemory(ur_context_handle_t Context,
186189
// "Addr" might be a host pointer
187190
ReportBadFree(Addr, GetCurrentBacktrace(), nullptr);
188191
}
189-
return UR_RESULT_ERROR_INVALID_ARGUMENT;
192+
if (getOptions().HaltOnError) {
193+
exitWithErrors();
194+
}
195+
return UR_RESULT_SUCCESS;
190196
}
191197

192198
if (Addr != AllocInfo->UserBegin) {
193199
ReportBadFree(Addr, GetCurrentBacktrace(), AllocInfo);
194-
return UR_RESULT_ERROR_INVALID_ARGUMENT;
200+
if (getOptions().HaltOnError) {
201+
exitWithErrors();
202+
}
203+
return UR_RESULT_SUCCESS;
195204
}
196205

197206
if (AllocInfo->IsReleased) {
198207
ReportDoubleFree(Addr, GetCurrentBacktrace(), AllocInfo);
199-
return UR_RESULT_ERROR_INVALID_ARGUMENT;
208+
if (getOptions().HaltOnError) {
209+
exitWithErrors();
210+
}
211+
return UR_RESULT_SUCCESS;
200212
}
201213

202214
AllocInfo->IsReleased = true;

source/loader/layers/sanitizer/asan/asan_options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ AsanOptions::AsanOptions() {
9090
SetBoolOption("detect_privates", DetectPrivates);
9191
SetBoolOption("print_stats", PrintStats);
9292
SetBoolOption("detect_leaks", DetectLeaks);
93+
SetBoolOption("halt_on_error", HaltOnError);
9394

9495
auto KV = OptionsEnvMap->find("quarantine_size_mb");
9596
if (KV != OptionsEnvMap->end()) {

source/loader/layers/sanitizer/asan/asan_options.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct AsanOptions {
2828
bool PrintStats = false;
2929
bool DetectKernelArguments = true;
3030
bool DetectLeaks = true;
31+
bool HaltOnError = true;
3132

3233
explicit AsanOptions();
3334
};

0 commit comments

Comments
 (0)