From 80965154324a931a6664ad13fcc0f7aa49efc6cd Mon Sep 17 00:00:00 2001 From: Binbin Date: Tue, 6 Feb 2024 19:41:02 +0800 Subject: [PATCH] Fix invalid dictNext usage when pubsubshard_channels became empty (#13033) After #12822, when pubsubshard_channels became empty, kvstoreDictDelete will delete the dict (which is the only one currently deleting dicts that become empty) and in the next loop, we will make an invalid call to dictNext. After the dict becomes empty, we break out of the loop without calling dictNext. --- src/pubsub.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pubsub.c b/src/pubsub.c index a2c28ddcb..afe28f59b 100644 --- a/src/pubsub.c +++ b/src/pubsub.c @@ -350,6 +350,9 @@ void pubsubShardUnsubscribeAllChannelsInSlot(unsigned int slot) { } dictReleaseIterator(iter); kvstoreDictDelete(server.pubsubshard_channels, slot, channel); + /* After the dict becomes empty, the dict will be deleted. + * We break out without calling dictNext. */ + if (!kvstoreDictSize(server.pubsubshard_channels, slot)) break; } dictReleaseIterator(di); }