1313 * - cache_miss_hook: Handle cache miss events
1414 * - cache_eviction_hook: Determine which object to evict
1515 * - cache_remove_hook: Clean up when objects are removed
16+ * - cache_free_hook: Free plugin resources
1617 *
1718 * The plugin cache delegates core cache operations to these hooks, enabling
1819 * flexible and extensible cache policies.
@@ -52,6 +53,7 @@ typedef struct pluginCache_params {
5253 cache_miss_hook_t cache_miss_hook ; ///< Cache miss handler function
5354 cache_eviction_hook_t cache_eviction_hook ; ///< Eviction decision function
5455 cache_remove_hook_t cache_remove_hook ; ///< Object removal handler function
56+ cache_free_hook_t cache_free_hook ; ///< Cache cleanup function
5557 char * cache_name ;
5658} pluginCache_params_t ;
5759
@@ -159,6 +161,10 @@ cache_t *pluginCache_init(const common_cache_params_t ccache_params,
159161 void * obj ;
160162 cache_remove_hook_t func ;
161163 } cache_remove_u ;
164+ union {
165+ void * obj ;
166+ cache_free_hook_t func ;
167+ } cache_free_u ;
162168
163169 cache_init_u .obj = dlsym (handle , "cache_init_hook" );
164170 params -> cache_init_hook = cache_init_u .func ;
@@ -175,6 +181,9 @@ cache_t *pluginCache_init(const common_cache_params_t ccache_params,
175181 cache_remove_u .obj = dlsym (handle , "cache_remove_hook" );
176182 params -> cache_remove_hook = cache_remove_u .func ;
177183
184+ cache_free_u .obj = dlsym (handle , "cache_free_hook" );
185+ params -> cache_free_hook = cache_free_u .func ;
186+
178187 // Initialize the plugin with cache parameters
179188 params -> data = params -> cache_init_hook (ccache_params );
180189
@@ -205,6 +214,9 @@ cache_t *pluginCache_init(const common_cache_params_t ccache_params,
205214 */
206215static void pluginCache_free (cache_t * cache ) {
207216 pluginCache_params_t * params = (pluginCache_params_t * )cache -> eviction_params ;
217+
218+ if (params -> cache_free_hook != NULL ) params -> cache_free_hook (params -> data );
219+
208220 if (params -> plugin_path != NULL ) free (params -> plugin_path );
209221 if (params -> cache_name != NULL ) free (params -> cache_name );
210222 free (cache -> eviction_params );
@@ -398,8 +410,10 @@ static void pluginCache_parse_params(cache_t *cache,
398410
399411 // Process recognized parameters
400412 if (strcasecmp (key , "plugin" ) == 0 || strcasecmp (key , "plugin_path" ) == 0 ) {
413+ if (params -> plugin_path != NULL ) free (params -> plugin_path );
401414 params -> plugin_path = strdup (value );
402415 } else if (strcasecmp (key , "cache_name" ) == 0 ) {
416+ if (params -> cache_name != NULL ) free (params -> cache_name );
403417 params -> cache_name = strdup (value );
404418 } else if (strcasecmp (key , "print" ) == 0 ) {
405419 printf ("current parameters: plugin_path=%s\n" , params -> plugin_path );
0 commit comments