Skip to content

Commit

Permalink
Fix memory leak in forgotten node ping ext code path (#1574)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
pieturin committed Jan 17, 2025
1 parent f685206 commit 5fc3a8f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5fc3a8f

Please sign in to comment.