diff --git a/src/ae.cpp b/src/ae.cpp index a23fb9dc8..d6fd1bc76 100644 --- a/src/ae.cpp +++ b/src/ae.cpp @@ -399,10 +399,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 58d0fe465..cb310af5d 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -1367,6 +1367,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) { dictEntry *kde; diff --git a/src/replication.cpp b/src/replication.cpp index 3fe5d9e9e..3823bc43f 100644 --- a/src/replication.cpp +++ b/src/replication.cpp @@ -3786,7 +3786,7 @@ private: redisMaster *m_mi = nullptr; }; -static thread_local ReplicaNestState *s_pstate = nullptr; +static thread_local std::unique_ptr s_pstate; bool FInReplicaReplay() { @@ -3799,7 +3799,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 c106bba8a..d5cb48c92 100644 --- a/src/server.h +++ b/src/server.h @@ -1085,10 +1085,13 @@ typedef struct clientReplyBlock { /* 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 { +struct redisDb { redisDb() : expireitr(nullptr) {}; + + ~redisDb(); + dict *pdict; /* The keyspace for this DB */ expireset *setexpire; expireset::setiter expireitr; @@ -1100,7 +1103,7 @@ typedef struct redisDb { 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 {