Skip to content

Commit ae35b9a

Browse files
committed
[Feat] Explicitly call python free
1 parent a24ad03 commit ae35b9a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/export_cache.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,23 @@ static void pypluginCache_free(cache_t* cache) {
167167
return;
168168
}
169169

170-
// Use smart pointer for automatic cleanup
171-
std::unique_ptr<pypluginCache_params_t, PypluginCacheParamsDeleter> params(
172-
static_cast<pypluginCache_params_t*>(cache->eviction_params));
170+
pypluginCache_params_t* params =
171+
static_cast<pypluginCache_params_t*>(cache->eviction_params);
172+
173+
// Explicitly call the cache_free_hook before cleanup
174+
if (!params->cache_free_hook.is_none()) {
175+
try {
176+
params->cache_free_hook(params->data);
177+
} catch (...) {
178+
// Ignore exceptions during cleanup to prevent double-fault
179+
}
180+
}
181+
182+
// Clean up the parameters
183+
delete params;
184+
cache->eviction_params = nullptr;
173185

174-
// The smart pointer destructor will handle cleanup automatically
186+
// Free the cache structure
175187
cache_struct_free(cache);
176188
}
177189

0 commit comments

Comments
 (0)