make extent_hooks static.
[folly.git] / folly / experimental / JemallocNodumpAllocator.cpp
index e2ce6d8c5061c48ff5fd6ebd73d2322618b778be..481efd000457d5d95a4ea0a68bd16e9c779607c6 100644 (file)
@@ -89,7 +89,13 @@ bool JemallocNodumpAllocator::extend_and_setup_arena() {
   }
 
   // Set the custom hook
-  hooks->alloc = &JemallocNodumpAllocator::alloc;
+  extent_hooks_ = *hooks;
+  extent_hooks_.alloc = &JemallocNodumpAllocator::alloc;
+  extent_hooks_t* new_hooks = &extent_hooks_;
+  if (auto ret = mallctl(
+          key.c_str(), nullptr, nullptr, &new_hooks, sizeof(new_hooks))) {
+    LOG(FATAL) << "Unable to set the hooks: " << errnoStr(ret);
+  }
 #endif
 
   return true;
@@ -113,6 +119,7 @@ chunk_alloc_t* JemallocNodumpAllocator::original_alloc_ = nullptr;
 void* JemallocNodumpAllocator::alloc(
     void* chunk,
 #else
+extent_hooks_t JemallocNodumpAllocator::extent_hooks_;
 extent_alloc_t* JemallocNodumpAllocator::original_alloc_ = nullptr;
 void* JemallocNodumpAllocator::alloc(
     extent_hooks_t* extent,