Skip to content

Commit

Permalink
kvstoreIteratorNext() wrongly reset iterator twice
Browse files Browse the repository at this point in the history
  • Loading branch information
moticless committed Mar 28, 2024
1 parent 14af031 commit f24444b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/kvstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,11 @@ void kvstoreIteratorRelease(kvstoreIterator *kvs_it) {
zfree(kvs_it);
}

/* Returns next dictionary from the iterator, or NULL if iteration is complete. */

/* Returns next dictionary from the iterator, or NULL if iteration is complete.
*
* - Takes care to reset the iter of the previous dict before moved to the next dict.
*/
dict *kvstoreIteratorNextDict(kvstoreIterator *kvs_it) {
if (kvs_it->next_didx == -1)
return NULL;
Expand Down Expand Up @@ -596,13 +600,15 @@ int kvstoreIteratorGetCurrentDictIndex(kvstoreIterator *kvs_it) {
dictEntry *kvstoreIteratorNext(kvstoreIterator *kvs_it) {
dictEntry *de = kvs_it->di.d ? dictNext(&kvs_it->di) : NULL;
if (!de) { /* No current dict or reached the end of the dictionary. */

/* Before we move to the next dict, function kvstoreIteratorNextDict()
* reset the iter of the previous dict. */
dict *d = kvstoreIteratorNextDict(kvs_it);

if (!d)
return NULL;

if (kvs_it->di.d) {
/* Before we move to the next dict, reset the iter of the previous dict. */
dictIterator *iter = &kvs_it->di;
dictResetIterator(iter);
/* In the safe iterator context, we may delete entries. */
freeDictIfNeeded(kvs_it->kvs, kvs_it->didx);
}
Expand Down

0 comments on commit f24444b

Please sign in to comment.