diff --git a/src/ae.cpp b/src/ae.cpp index 68b1cf20d..25898007e 100644 --- a/src/ae.cpp +++ b/src/ae.cpp @@ -403,10 +403,18 @@ extern "C" void aeDeleteEventLoop(aeEventLoop *eventLoop) { aeApiFree(eventLoop); zfree(eventLoop->events); zfree(eventLoop->fired); - zfree(eventLoop); fastlock_free(&eventLoop->flock); close(eventLoop->fdCmdRead); close(eventLoop->fdCmdWrite); + + auto *te = eventLoop->timeEventHead; + while (te) + { + auto *teNext = te->next; + zfree(te); + te = teNext; + } + zfree(eventLoop); } extern "C" void aeStop(aeEventLoop *eventLoop) { diff --git a/src/db.cpp b/src/db.cpp index 4cc54027c..2423bbf0e 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -1495,6 +1495,14 @@ void setExpire(client *c, redisDb *db, robj *key, robj *subkey, long long when) rememberSlaveKeyWithExpire(db,key); } +redisDb::~redisDb() +{ + dictRelease(watched_keys); + dictRelease(ready_keys); + dictRelease(blocking_keys); + listRelease(defrag_later); +} + void setExpire(client *c, redisDb *db, robj *key, expireEntry &&e) { serverAssert(GlobalLocksAcquired()); diff --git a/src/replication.cpp b/src/replication.cpp index b8c61aef5..1d52e6d24 100644 --- a/src/replication.cpp +++ b/src/replication.cpp @@ -3849,7 +3849,7 @@ private: redisMaster *m_mi = nullptr; }; -static thread_local ReplicaNestState *s_pstate = nullptr; +static thread_local std::unique_ptr s_pstate; bool FInReplicaReplay() { @@ -3862,7 +3862,7 @@ static std::unordered_map g_mapmvcc; void replicaReplayCommand(client *c) { if (s_pstate == nullptr) - s_pstate = new (MALLOC_LOCAL) ReplicaNestState; + s_pstate = std::make_unique(); // the replay command contains two arguments: // 1: The UUID of the source diff --git a/src/server.h b/src/server.h index d1bce13fd..c9f3d0dda 100644 --- a/src/server.h +++ b/src/server.h @@ -1400,7 +1400,7 @@ public: /* Redis database representation. There are multiple databases identified * by integers from 0 (the default database) up to the max configured * database. The database number is the 'id' field in the structure. */ -typedef struct redisDb : public redisDbPersistentDataSnapshot +struct redisDb : public redisDbPersistentDataSnapshot { // Legacy C API, Do not add more friend void tryResizeHashTables(int); @@ -1425,6 +1425,7 @@ typedef struct redisDb : public redisDbPersistentDataSnapshot : expireitr(nullptr) {} void initialize(int id); + virtual ~redisDb(); void dbOverwriteCore(redisDb::iter itr, robj *key, robj *val, bool fUpdateMvcc, bool fRemoveExpire); @@ -1477,7 +1478,7 @@ public: long long last_expire_set; /* when the last expire was set */ double avg_ttl; /* Average TTL, just for stats */ list *defrag_later; /* List of key names to attempt to defrag one by one, gradually. */ -} redisDb; +}; /* Client MULTI/EXEC state */ typedef struct multiCmd {