Skip to content

Commit c144eb7

Browse files
authored
Enhance param parse for 3L and LRB (#204)
1 parent af4d747 commit c144eb7

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

libCacheSim/cache/eviction/3LCache/ThreeLCache_Interface.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,9 @@ cache_t *ThreeLCache_init(const common_cache_params_t ccache_params,
9292
ThreeLCache_params_t *params = my_malloc(ThreeLCache_params_t);
9393
cache->eviction_params = params;
9494

95+
ThreeLCache_parse_params(cache, DEFAULT_PARAMS);
9596
if (cache_specific_params != NULL) {
9697
ThreeLCache_parse_params(cache, cache_specific_params);
97-
} else {
98-
ThreeLCache_parse_params(cache, DEFAULT_PARAMS);
9998
}
10099

101100
auto *ThreeLCache = new ThreeLCache::ThreeLCacheCache();
@@ -131,6 +130,9 @@ static void ThreeLCache_free(cache_t *cache) {
131130
static_cast<ThreeLCache::ThreeLCacheCache *>(params->ThreeLCache_cache);
132131
delete ThreeLCache;
133132
free(cache->to_evict_candidate);
133+
if (params->objective != NULL) {
134+
free(params->objective);
135+
}
134136
my_free(sizeof(ThreeLCache_params_t), params);
135137
cache_struct_free(cache);
136138
}
@@ -340,6 +342,9 @@ static void ThreeLCache_parse_params(cache_t *cache,
340342
}
341343

342344
if (strcasecmp(key, "objective") == 0) {
345+
if (params->objective != NULL) {
346+
free(params->objective);
347+
}
343348
params->objective = strdup(value);
344349
if (params->objective == NULL) {
345350
ERROR("out of memory %s\n", strerror(errno));

libCacheSim/cache/eviction/LRB/LRB_Interface.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ cache_t *LRB_init(const common_cache_params_t ccache_params,
9595
LRB_params_t *params = my_malloc(LRB_params_t);
9696
cache->eviction_params = params;
9797

98+
LRB_parse_params(cache, DEFAULT_PARAMS);
9899
if (cache_specific_params != NULL) {
99100
LRB_parse_params(cache, cache_specific_params);
100-
} else {
101-
LRB_parse_params(cache, DEFAULT_PARAMS);
102101
}
103102

104103
auto *lrb = new lrb::LRBCache();
@@ -133,6 +132,9 @@ static void LRB_free(cache_t *cache) {
133132
auto *LRB = static_cast<lrb::LRBCache *>(params->LRB_cache);
134133
delete LRB;
135134
free(cache->to_evict_candidate);
135+
if (params->objective != NULL) {
136+
free(params->objective);
137+
}
136138
my_free(sizeof(LRB_params_t), params);
137139
cache_struct_free(cache);
138140
}
@@ -332,6 +334,9 @@ static void LRB_parse_params(cache_t *cache,
332334
}
333335

334336
if (strcasecmp(key, "objective") == 0) {
337+
if (params->objective != NULL) {
338+
free(params->objective);
339+
}
335340
params->objective = strdup(value);
336341
if (params->objective == NULL) {
337342
ERROR("out of memory %s\n", strerror(errno));

0 commit comments

Comments
 (0)