Skip to content

Commit f086f36

Browse files
authored
Merge pull request #1312 from AllanZyne/fix-coverity/sanitizer-layer
[SanitizerLayer] Fix resource leaks in "san_utils.cpp"
2 parents c0b1f13 + e4b5b89 commit f086f36

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

source/loader/layers/sanitizer/asan_interceptor.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,6 @@ ur_result_t SanitizerInterceptor::enqueueMemSetShadow(
366366
static auto MemSet =
367367
(void *(*)(void *, int, size_t))GetMemFunctionPointer("memset");
368368
if (!MemSet) {
369-
context.logger.error(
370-
"Failed to get 'memset' function from libc.so.6");
371369
return UR_RESULT_ERROR_UNKNOWN;
372370
}
373371

source/loader/layers/sanitizer/linux/san_utils.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
#include "common.hpp"
15+
#include "ur_sanitizer_layer.hpp"
1516

1617
#include <asm/param.h>
1718
#include <dlfcn.h>
@@ -22,7 +23,7 @@ extern "C" __attribute__((weak)) void __asan_init(void);
2223

2324
namespace ur_sanitizer_layer {
2425

25-
bool IsInASanContext() { return __asan_init != nullptr; }
26+
bool IsInASanContext() { return (void *)__asan_init != nullptr; }
2627

2728
static bool ReserveShadowMem(uptr Addr, uptr Size) {
2829
Size = RoundUpTo(Size, EXEC_PAGESIZE);
@@ -71,13 +72,14 @@ bool DestroyShadowMem() {
7172
}
7273

7374
void *GetMemFunctionPointer(const char *FuncName) {
74-
void *handle = dlopen(LIBC_SO, RTLD_LAZY);
75+
void *handle = dlopen(LIBC_SO, RTLD_LAZY | RTLD_NOLOAD);
7576
if (!handle) {
76-
return (void *)nullptr;
77+
context.logger.error("Failed to dlopen {}", LIBC_SO);
78+
return nullptr;
7779
}
78-
void *ptr = dlsym(handle, FuncName);
80+
auto ptr = dlsym(handle, FuncName);
7981
if (!ptr) {
80-
return (void *)nullptr;
82+
context.logger.error("Failed to get '{}' from {}", FuncName, LIBC_SO);
8183
}
8284
return ptr;
8385
}

0 commit comments

Comments
 (0)