https://github.com/antirez/redis/blob/c49fb47fbe0086dc9e44b8ac39128beb7ec1bf3a/src/dict.c#L174 I am wondering if call dictExpand multi times until d->ht[1] is not NULL, and call it once again, will the codes above lead to memory leak? It didn't free the origin one,just assign a new hash table to it. Call function chain is dictAddRaw->_dictKeyIndex->_dictExpandIfNeeded->dictExpand

Comment From: WiFeng

No problems.

#define dictIsRehashing(d) ((d)->rehashidx != -1)
/* Expand or create the hash table */
int dictExpand(dict *d, unsigned long size)
{
    /* the size is invalid if it is smaller than the number of
     * elements already inside the hash table */
    if (dictIsRehashing(d) || d->ht[0].used > size)
        return DICT_ERR;
    /* Prepare a second hash table for incremental rehashing */
    d->ht[1] = n;
    d->rehashidx = 0;
    return DICT_OK;

Comment From: woodliu

No problems.

```

define dictIsRehashing(d) ((d)->rehashidx != -1)

```

/* Expand or create the hash table */ int dictExpand(dict *d, unsigned long size) { /* the size is invalid if it is smaller than the number of * elements already inside the hash table */ if (dictIsRehashing(d) || d->ht[0].used > size) return DICT_ERR;

/* Prepare a second hash table for incremental rehashing */ d->ht[1] = n; d->rehashidx = 0; return DICT_OK;

So When it is rehashing, this function will return directly. Thank you!