From ae35b9ac794374a94e83861d5a809f9607e34f1e Mon Sep 17 00:00:00 2001 From: Percy Date: Sun, 10 Aug 2025 23:26:36 -0400 Subject: [PATCH] [Feat] Explicitly call python free --- src/export_cache.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/export_cache.cpp b/src/export_cache.cpp index d7ec858..4c25ae7 100644 --- a/src/export_cache.cpp +++ b/src/export_cache.cpp @@ -167,11 +167,23 @@ static void pypluginCache_free(cache_t* cache) { return; } - // Use smart pointer for automatic cleanup - std::unique_ptr params( - static_cast(cache->eviction_params)); + pypluginCache_params_t* params = + static_cast(cache->eviction_params); + + // Explicitly call the cache_free_hook before cleanup + if (!params->cache_free_hook.is_none()) { + try { + params->cache_free_hook(params->data); + } catch (...) { + // Ignore exceptions during cleanup to prevent double-fault + } + } + + // Clean up the parameters + delete params; + cache->eviction_params = nullptr; - // The smart pointer destructor will handle cleanup automatically + // Free the cache structure cache_struct_free(cache); }