Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include <assert.h>

#include <map>
Expand Down Expand Up @@ -92,10 +92,9 @@
ThreeLCache_params_t *params = my_malloc(ThreeLCache_params_t);
cache->eviction_params = params;

ThreeLCache_parse_params(cache, DEFAULT_PARAMS);
if (cache_specific_params != NULL) {
ThreeLCache_parse_params(cache, cache_specific_params);
} else {
ThreeLCache_parse_params(cache, DEFAULT_PARAMS);
}

auto *ThreeLCache = new ThreeLCache::ThreeLCacheCache();
Expand Down Expand Up @@ -131,6 +130,9 @@
static_cast<ThreeLCache::ThreeLCacheCache *>(params->ThreeLCache_cache);
delete ThreeLCache;
free(cache->to_evict_candidate);
if (params->objective != NULL) {
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

Adding a check and free for 'objective' in the free function reinforces memory safety; ensure this pattern is uniformly applied across all similar modules.

Copilot uses AI. Check for mistakes.
free(params->objective);
}
my_free(sizeof(ThreeLCache_params_t), params);
cache_struct_free(cache);
}
Expand Down Expand Up @@ -340,6 +342,9 @@
}

if (strcasecmp(key, "objective") == 0) {
if (params->objective != NULL) {
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

Properly freeing the existing 'objective' before assigning a new value prevents memory leaks; this update maintains consistency with similar patterns in the LRB module.

Copilot uses AI. Check for mistakes.
free(params->objective);
}
params->objective = strdup(value);
if (params->objective == NULL) {
ERROR("out of memory %s\n", strerror(errno));
Expand Down
9 changes: 7 additions & 2 deletions libCacheSim/cache/eviction/LRB/LRB_Interface.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@


#include <assert.h>
Expand Down Expand Up @@ -95,10 +95,9 @@
LRB_params_t *params = my_malloc(LRB_params_t);
cache->eviction_params = params;

LRB_parse_params(cache, DEFAULT_PARAMS);
if (cache_specific_params != NULL) {
LRB_parse_params(cache, cache_specific_params);
} else {
LRB_parse_params(cache, DEFAULT_PARAMS);
}

auto *lrb = new lrb::LRBCache();
Expand Down Expand Up @@ -133,6 +132,9 @@
auto *LRB = static_cast<lrb::LRBCache *>(params->LRB_cache);
delete LRB;
free(cache->to_evict_candidate);
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

Including an explicit check and free for 'objective' in the free function helps prevent memory leaks; verify that the allocation lifecycle for 'objective' is consistently managed across code paths.

Suggested change
free(cache->to_evict_candidate);
free(cache->to_evict_candidate);
// Ensure that 'objective' is freed to prevent memory leaks.

Copilot uses AI. Check for mistakes.
if (params->objective != NULL) {
free(params->objective);
}
my_free(sizeof(LRB_params_t), params);
cache_struct_free(cache);
}
Expand Down Expand Up @@ -332,6 +334,9 @@
}

if (strcasecmp(key, "objective") == 0) {
if (params->objective != NULL) {
free(params->objective);
Copy link

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

Freeing the existing 'objective' before reassigning it avoids memory leaks; this practice is consistent with robust memory management.

Suggested change
free(params->objective);
free(params->objective);
params->objective = NULL;

Copilot uses AI. Check for mistakes.
}
params->objective = strdup(value);
if (params->objective == NULL) {
ERROR("out of memory %s\n", strerror(errno));
Expand Down
Loading