diff --git a/core/hakmem_tiny_superslab.c b/core/hakmem_tiny_superslab.c index 21b01eb7..0f8ef63c 100644 --- a/core/hakmem_tiny_superslab.c +++ b/core/hakmem_tiny_superslab.c @@ -117,6 +117,12 @@ static void log_superslab_oom_once(size_t ss_size, size_t alloc_size, int err) { if (logged) return; logged = 1; + // CRITICAL FIX: Increment lock depth FIRST before any LIBC calls + // fopen/fclose/getrlimit/fprintf all may call malloc internally + // Must bypass HAKMEM wrapper to avoid header mismatch crash + extern __thread int g_hakmem_lock_depth; + g_hakmem_lock_depth++; // Force wrapper to use __libc_malloc + struct rlimit rl = {0}; if (getrlimit(RLIMIT_AS, &rl) != 0) { rl.rlim_cur = RLIM_INFINITY; @@ -125,10 +131,6 @@ static void log_superslab_oom_once(size_t ss_size, size_t alloc_size, int err) { unsigned long vm_size_kb = 0; unsigned long vm_rss_kb = 0; - // CRITICAL FIX: fopen/fclose use GLIBC malloc/free internally - // Must bypass HAKMEM wrapper to avoid header mismatch crash - extern __thread int g_hakmem_lock_depth; - g_hakmem_lock_depth++; // Force wrapper to use __libc_malloc FILE* status = fopen("/proc/self/status", "r"); if (status) { char line[256];