From 818dfeb3dfcbc1627cebcee743f00ea131471626 Mon Sep 17 00:00:00 2001 From: Aleksey Date: Fri, 18 Mar 2022 13:27:44 +0300 Subject: [PATCH] github issue#74 fix Intercept Queue callbacks are checked for null. If the user forgets to initialize one of them, random code could be called. That leads to very tricky memory corruption bugs. I met the condition when the program restarted in the context pool destructor. --- src/core/context_pool.h | 4 +++- src/core/intercept_queue.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/context_pool.h b/src/core/context_pool.h index c5c45cc5..c9842881 100644 --- a/src/core/context_pool.h +++ b/src/core/context_pool.h @@ -156,7 +156,9 @@ class ContextPool { entry_t* entry = reinterpret_cast(ptr); Context::Destroy(entry->context); } - free(array_); + if (constructed_) { + free(array_); + } } char* GetArrayPtr(const uint32_t& index) { return array_ + (index % array_size_bytes_); } diff --git a/src/core/intercept_queue.cpp b/src/core/intercept_queue.cpp index 720026ca..bdad0393 100644 --- a/src/core/intercept_queue.cpp +++ b/src/core/intercept_queue.cpp @@ -29,7 +29,7 @@ void InterceptQueue::HsaIntercept(HsaApiTable* table) { } InterceptQueue::mutex_t InterceptQueue::mutex_; -rocprofiler_queue_callbacks_t InterceptQueue::callbacks_ = {}; +rocprofiler_queue_callbacks_t InterceptQueue::callbacks_ = {NULL,NULL,NULL}; void* InterceptQueue::callback_data_ = NULL; std::atomic InterceptQueue::dispatch_callback_{NULL}; InterceptQueue::obj_map_t InterceptQueue::obj_map_{};