@@ -47,6 +47,7 @@ extern "C" {
4747 */
4848typedef struct pluginCache_params {
4949 char * plugin_path ; ///< Path to the plugin shared library
50+ void * handle ; ///< Handle to the loaded plugin library
5051 void * data ; ///< Plugin's internal data structure
5152 cache_init_hook_t cache_init_hook ; ///< Plugin initialization function
5253 cache_hit_hook_t cache_hit_hook ; ///< Cache hit handler function
@@ -139,6 +140,7 @@ cache_t *pluginCache_init(const common_cache_params_t ccache_params,
139140 ERROR ("Failed to load plugin %s: %s\n" , params -> plugin_path , dlerror ());
140141 exit (1 );
141142 }
143+ params -> handle = handle ;
142144
143145 // Load hook functions from the plugin using unions to avoid pedantic warnings
144146 union {
@@ -216,7 +218,8 @@ static void pluginCache_free(cache_t *cache) {
216218 pluginCache_params_t * params = (pluginCache_params_t * )cache -> eviction_params ;
217219
218220 if (params -> cache_free_hook != NULL ) params -> cache_free_hook (params -> data );
219-
221+ if (params -> handle != NULL )
222+ dlclose (params -> handle ); // Close the plugin shared library handle
220223 if (params -> plugin_path != NULL ) free (params -> plugin_path );
221224 if (params -> cache_name != NULL ) free (params -> cache_name );
222225 free (cache -> eviction_params );
@@ -410,6 +413,12 @@ static void pluginCache_parse_params(cache_t *cache,
410413
411414 // Process recognized parameters
412415 if (strcasecmp (key , "plugin" ) == 0 || strcasecmp (key , "plugin_path" ) == 0 ) {
416+ // Validate plugin path is not empty
417+ if (strlen (value ) == 0 ) {
418+ ERROR ("Parameter 'plugin_path' cannot be empty in cache '%s'\n" ,
419+ cache -> cache_name );
420+ exit (1 );
421+ }
413422 if (params -> plugin_path != NULL ) free (params -> plugin_path );
414423 params -> plugin_path = strdup (value );
415424 } else if (strcasecmp (key , "cache_name" ) == 0 ) {
0 commit comments