Skip to content

Fix: add cache free hook and default param free#253

Merged
1a1a11a merged 3 commits intodevelopfrom
hxia/plugin
Jul 10, 2025
Merged

Fix: add cache free hook and default param free#253
1a1a11a merged 3 commits intodevelopfrom
hxia/plugin

Conversation

@haochengxia
Copy link
Copy Markdown
Collaborator

@haochengxia haochengxia commented Jul 10, 2025

Subsequent PR of #252, aimed at better memory management

  • Free the default parameter
  • Add cahce_free_hook

@haochengxia haochengxia requested a review from Copilot July 10, 2025 12:52
@haochengxia haochengxia changed the title Add optional cache free hook Fix: add cache free hook and default param free Jul 10, 2025

This comment was marked as outdated.

@haochengxia haochengxia requested a review from Copilot July 10, 2025 13:22

This comment was marked as outdated.

@haochengxia haochengxia requested a review from Copilot July 10, 2025 13:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new hook for releasing plugin resources and enhances parameter cleanup in the plugin-based cache implementation.

  • Adds cache_free_hook to the plugin API and invokes it on cache destruction
  • Tracks and closes the dynamic library handle for plugins
  • Validates and frees previously set plugin_path and cache_name parameters

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
libCacheSim/include/libCacheSim/plugin.h Defined cache_free_hook_t in the public plugin API
libCacheSim/cache/eviction/plugin_cache.c Loaded, stored, and called the new free hook; managed dlopen handle; validated/free parameters
example/plugin_v2/plugin_lru.cpp Implemented cache_free_hook in the LRU plugin example
example/plugin_v2/README.md Documented the new cache_free_hook in usage section
Comments suppressed due to low confidence (2)

libCacheSim/cache/eviction/plugin_cache.c:220

  • There are no existing tests to verify that the free hook is invoked and the plugin handle is closed. Consider adding unit tests that register a dummy plugin and confirm the free hook and dlclose are called.
  if (params->cache_free_hook != NULL) params->cache_free_hook(params->data);

libCacheSim/cache/eviction/plugin_cache.c:417

  • Using cache->cache_name in the error message before cache_name is set can lead to a NULL dereference. Consider validating or assigning a default name before reporting errors.
      if (strlen(value) == 0) {

cache_remove_u.obj = dlsym(handle, "cache_remove_hook");
params->cache_remove_hook = cache_remove_u.func;

cache_free_u.obj = dlsym(handle, "cache_free_hook");
Copy link

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result of dlsym for cache_free_hook isn't checked; if the symbol load fails unexpectedly, you may call a garbage pointer. Add a NULL check or error log similar to other hooks.

Suggested change
cache_free_u.obj = dlsym(handle, "cache_free_hook");
cache_free_u.obj = dlsym(handle, "cache_free_hook");
if (cache_free_u.obj == NULL) {
fprintf(stderr, "Error: Failed to load symbol 'cache_free_hook'.\n");
return -1; // or appropriate error handling
}

Copilot uses AI. Check for mistakes.
@haochengxia haochengxia requested a review from 1a1a11a July 10, 2025 13:46
@1a1a11a 1a1a11a merged commit 3a9b061 into develop Jul 10, 2025
9 checks passed
@1a1a11a 1a1a11a deleted the hxia/plugin branch July 10, 2025 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants