From 166e0d80f56b7ac1a44ce07a5701b22208fdf840 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Tue, 24 May 2022 14:22:16 +0200 Subject: [PATCH] Fixed cache->jit memory leak 1. `cache->jit = new randomx::JitCompiler();` - succeeds 2. `cache->memory = (uint8_t*)randomx::LargePageAllocator::allocMemory(randomx::CacheSize);` - fails 3. `if (cache && cache->memory == nullptr) randomx_release_cache(cache);` is executed 4. randomx_release_cache checks `if (cache->memory != nullptr)` and does nothing 5. cache->jit stays allocated --- src/randomx.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/randomx.cpp b/src/randomx.cpp index 0b33806..7daaa46 100644 --- a/src/randomx.cpp +++ b/src/randomx.cpp @@ -134,9 +134,7 @@ extern "C" { void randomx_release_cache(randomx_cache* cache) { assert(cache != nullptr); - if (cache->memory != nullptr) { - cache->dealloc(cache); - } + cache->dealloc(cache); delete cache; }