Repository: valkey-io/valkey
File: src/acl.c (C)

Code before:
         * default user configuration in the old one. */
        user *new_default = ACLGetUserByName("default", 7);
        if (!new_default) {
            new_default = ACLCreateDefaultUser();
        }

        ACLCopyUser(DefaultUser, new_default);
        ACLFreeUser(new_default);
        raxInsert(Users, (unsigned char *)"default", 7, DefaultUser, NULL);
        raxRemove(old_users, (unsigned char *)"default", 7, NULL);

        /* If there are some subscribers, we need to check if we need to drop some clients. */
        rax *user_channels = NULL;
        if (pubsubTotalSubscriptions() > 0) {
            user_channels = raxNew();
        }

        listIter li;
        listNode *ln;

        listRewind(server.clients, &li);
        while ((ln = listNext(&li)) != NULL) {
            client *c = listNodeValue(ln);
            if (!c->user) {
                /* Some clients, e.g. the one from the primary to a replica, don't have a user
                 * associated with them.*/
                continue;
            }
            user *original = c->user;
            list *channels = NULL;
            user *new_user = ACLGetUserByName(c->user->name, sdslen(c->user->name));
            if (new_user && user_channels) {
                if (!raxFind(user_channels, (unsigned char *)(new_user->name), sdslen(new_user->name),
                             (void **)&channels)) {
                    channels = getUpcomingChannelList(new_user, original);
                    raxInsert(user_channels, (unsigned char *)(new_user->name), sdslen(new_user->name), channels, NULL);
                }
            }
            /* When the new channel list is NULL, it means the new user's channel list is a superset of the old user's
             * list. */
            if (!new_user || (channels && ACLShouldKillPubsubClient(c, channels))) {
                freeClient(c);
                continue;
            }
            c->user = new_user;
        }

        if (user_channels) raxFreeWithCallback(user_channels, listReleaseVoid);
        raxFreeWithCallback(old_users, ACLFreeUserVoid);
        sdsfree(errors);
        return NULL;

Review comment (suggestion):
```suggestion
                /* Some clients, e.g. the one from the primary to replica, don't have a user
                 * associated with them. */
```

Code after:
         * default user configuration in the old one. */
        user *new_default = ACLGetUserByName("default", 7);
        if (!new_default) {
            new_default = ACLCreateDefaultUser();
        }

        ACLCopyUser(DefaultUser, new_default);
        ACLFreeUser(new_default);
        raxInsert(Users, (unsigned char *)"default", 7, DefaultUser, NULL);
        raxRemove(old_users, (unsigned char *)"default", 7, NULL);

        /* If there are some subscribers, we need to check if we need to drop some clients. */
        rax *user_channels = NULL;
        if (pubsubTotalSubscriptions() > 0) {
            user_channels = raxNew();
        }

        listIter li;
        listNode *ln;

        listRewind(server.clients, &li);
        while ((ln = listNext(&li)) != NULL) {
            client *c = listNodeValue(ln);
            /* Some clients, e.g. the one from the primary to replica, don't have a user
             * associated with them. */
            if (!c->user) continue;
            user *original = c->user;
            list *channels = NULL;
            user *new_user = ACLGetUserByName(c->user->name, sdslen(c->user->name));
            if (new_user && user_channels) {
                if (!raxFind(user_channels, (unsigned char *)(new_user->name), sdslen(new_user->name),
                             (void **)&channels)) {
                    channels = getUpcomingChannelList(new_user, original);
                    raxInsert(user_channels, (unsigned char *)(new_user->name), sdslen(new_user->name), channels, NULL);
                }
            }
            /* When the new channel list is NULL, it means the new user's channel list is a superset of the old user's
             * list. */
            if (!new_user || (channels && ACLShouldKillPubsubClient(c, channels))) {
                freeClient(c);
                continue;
            }
            c->user = new_user;
        }

        if (user_channels) raxFreeWithCallback(user_channels, listReleaseVoid);
        raxFreeWithCallback(old_users, ACLFreeUserVoid);
        sdsfree(errors);
        return NULL;
    } else {
        raxFreeWithCallback(Users, ACLFreeUserVoid);