Skip to content

Commit

Permalink
Merge pull request #1312 from AllanZyne/fix-coverity/sanitizer-layer
Browse files Browse the repository at this point in the history
[SanitizerLayer] Fix resource leaks in "san_utils.cpp"
  • Loading branch information
pbalcer authored Feb 6, 2024
2 parents c0b1f13 + e4b5b89 commit f086f36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 0 additions & 2 deletions source/loader/layers/sanitizer/asan_interceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,6 @@ ur_result_t SanitizerInterceptor::enqueueMemSetShadow(
static auto MemSet =
(void *(*)(void *, int, size_t))GetMemFunctionPointer("memset");
if (!MemSet) {
context.logger.error(
"Failed to get 'memset' function from libc.so.6");
return UR_RESULT_ERROR_UNKNOWN;
}

Expand Down
12 changes: 7 additions & 5 deletions source/loader/layers/sanitizer/linux/san_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

#include "common.hpp"
#include "ur_sanitizer_layer.hpp"

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

namespace ur_sanitizer_layer {

bool IsInASanContext() { return __asan_init != nullptr; }
bool IsInASanContext() { return (void *)__asan_init != nullptr; }

static bool ReserveShadowMem(uptr Addr, uptr Size) {
Size = RoundUpTo(Size, EXEC_PAGESIZE);
Expand Down Expand Up @@ -71,13 +72,14 @@ bool DestroyShadowMem() {
}

void *GetMemFunctionPointer(const char *FuncName) {
void *handle = dlopen(LIBC_SO, RTLD_LAZY);
void *handle = dlopen(LIBC_SO, RTLD_LAZY | RTLD_NOLOAD);
if (!handle) {
return (void *)nullptr;
context.logger.error("Failed to dlopen {}", LIBC_SO);
return nullptr;
}
void *ptr = dlsym(handle, FuncName);
auto ptr = dlsym(handle, FuncName);
if (!ptr) {
return (void *)nullptr;
context.logger.error("Failed to get '{}' from {}", FuncName, LIBC_SO);
}
return ptr;
}
Expand Down

0 comments on commit f086f36

Please sign in to comment.