From 5fc3a8f150b345873f357d2f890ab8087aca6d06 Mon Sep 17 00:00:00 2001 From: Pierre <105686771+pieturin@users.noreply.github.com> Date: Thu, 16 Jan 2025 15:38:15 -0800 Subject: [PATCH] Fix memory leak in forgotten node ping ext code path (#1574) When processing a cluster bus PING extension, there is a memory leak when adding a new key to the `nodes_black_list` dict. We now make sure to free the key `sds` if the dict did not take ownership of it. Signed-off-by: Pierre Turin --- src/cluster.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cluster.c b/src/cluster.c index 207828450e..1d1879def7 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -2681,6 +2681,10 @@ void clusterProcessPingExtensions(clusterMsg *hdr, clusterLink *link) { if (n && n != myself && !(nodeIsSlave(myself) && myself->slaveof == n)) { sds id = sdsnewlen(forgotten_node_ext->name, CLUSTER_NAMELEN); dictEntry *de = dictAddOrFind(server.cluster->nodes_black_list, id); + if (dictGetKey(de) != id) { + /* The dict did not take ownership of the id string, so we need to free it. */ + sdsfree(id); + } uint64_t expire = server.unixtime + ntohu64(forgotten_node_ext->ttl); dictSetUnsignedIntegerVal(de, expire); clusterDelNode(n);