From b6f871cf42f5d97e1d6ce81e0429cf4a8f204d31 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 13 Dec 2016 16:27:13 +0100 Subject: [PATCH] Writable slaves expires: fix leak in key tracking. We need to use a dictionary type that frees the key, since we copy the keys in the dictionary we use to track expires created in the slave side. --- src/expire.c | 13 +++++++++++-- src/server.h | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/expire.c b/src/expire.c index b05bf9f1..637139f6 100644 --- a/src/expire.c +++ b/src/expire.c @@ -315,8 +315,17 @@ void expireSlaveKeys(void) { /* Track keys that received an EXPIRE or similar command in the context * of a writable slave. */ void rememberSlaveKeyWithExpire(redisDb *db, robj *key) { - if (slaveKeysWithExpire == NULL) - slaveKeysWithExpire = dictCreate(&keyptrDictType,NULL); + if (slaveKeysWithExpire == NULL) { + static dictType dt = { + dictSdsHash, /* hash function */ + NULL, /* key dup */ + NULL, /* val dup */ + dictSdsKeyCompare, /* key compare */ + dictSdsDestructor, /* key destructor */ + NULL /* val destructor */ + }; + slaveKeysWithExpire = dictCreate(&dt,NULL); + } if (db->id > 63) return; dictEntry *de = dictAddOrFind(slaveKeysWithExpire,key->ptr); diff --git a/src/server.h b/src/server.h index 5d3be585..2a61ea41 100644 --- a/src/server.h +++ b/src/server.h @@ -1742,6 +1742,11 @@ void evictionPoolAlloc(void); unsigned long LFUGetTimeInMinutes(void); uint8_t LFULogIncr(uint8_t value); +/* Keys hashing / comparison functions for dict.c hash tables. */ +unsigned int dictSdsHash(const void *key); +int dictSdsKeyCompare(void *privdata, const void *key1, const void *key2); +void dictSdsDestructor(void *privdata, void *val); + /* Git SHA1 */ char *redisGitSHA1(void); char *redisGitDirty(void);