From 57f160707e8f2e7b94319350f376db43ffeae3cc Mon Sep 17 00:00:00 2001
From: antoniofilipovic <filipovicantonio1998@gmail.com>
Date: Thu, 8 Feb 2024 10:43:58 +0100
Subject: [PATCH] fix bug - hardcoded wrong arena

---
 src/memory/global_memory_control.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/memory/global_memory_control.cpp b/src/memory/global_memory_control.cpp
index 43a34f241..b378bd6fb 100644
--- a/src/memory/global_memory_control.cpp
+++ b/src/memory/global_memory_control.cpp
@@ -224,18 +224,19 @@ void SetHooks() {
       LOG_FATAL("Error setting custom hooks for jemalloc arena {}", i);
     }
   }
+  auto last_arena = n_arenas;
   // For oversize arena, no need to read hooks, it will be intialized
   // with arena, just set our custom hooks
-  std::string func_name = "arena." + std::to_string(8) + ".extent_hooks";
+  std::string func_name = "arena." + std::to_string(last_arena) + ".extent_hooks";
 
   if (err) {
-    LOG_FATAL("Error setting jemalloc hooks for jemalloc arena {}", 8);
+    LOG_FATAL("Error setting jemalloc hooks for jemalloc arena {}", last_arena);
   }
 
   err = mallctl(func_name.c_str(), nullptr, nullptr, &new_hooks, sizeof(new_hooks));
 
   if (err) {
-    LOG_FATAL("Error setting custom hooks for jemalloc arena {}", 8);
+    LOG_FATAL("Error setting custom hooks for jemalloc oversize threshold arena {}", last_arena);
   }
 
 #endif