summaryrefslogtreecommitdiff
path: root/cache.c
diff options
context:
space:
mode:
authorbitground <70304874+bitground@users.noreply.github.com>2020-09-14 17:03:09 +0800
committerdormando <dormando@rydia.net>2020-10-26 16:36:00 -0700
commitb031143f8ab61296ddbf6c4470c5dcdbf7ae588b (patch)
tree39ad84ea0e932ddfd496b6543b5880a0f6fab53b /cache.c
parent6b319c8c7a29e9c353dec83dc92f01905f6c8966 (diff)
downloadmemcached-b031143f8ab61296ddbf6c4470c5dcdbf7ae588b.tar.gz
Fix over-freeing in internal object cache
When returning item to the cache and the items allocated exceeded cache->limit, we should free the item and not put it to the cache. The current code will free any item that tried returned to the cache when cache->total < cache->limit which is true in most cases if the total objects has never exceeded the limit.
Diffstat (limited to 'cache.c')
-rw-r--r--cache.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/cache.c b/cache.c
index 18dc8b7..95548e7 100644
--- a/cache.c
+++ b/cache.c
@@ -142,7 +142,7 @@ void do_cache_free(cache_t *cache, void *ptr) {
}
ptr = pre;
#endif
- if (cache->limit > cache->total) {
+ if (cache->limit != 0 && cache->limit < cache->total) {
/* Allow freeing in case the limit was revised downward */
if (cache->destructor) {
cache->destructor(ptr, NULL);