Skip to content

Commit

Permalink
Fix memory leak in forgotten node ping ext code path (valkey-io#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]>
Signed-off-by: proost <[email protected]>
  • Loading branch information
pieturin authored and proost committed Jan 17, 2025
1 parent fda1e1b commit 6d6a9f7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2936,6 +2936,10 @@ void clusterProcessPingExtensions(clusterMsg *hdr, clusterLink *link) {
if (n && n != myself && !(nodeIsReplica(myself) && myself->replicaof == 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 6d6a9f7

Please sign in to comment.