diff --git a/src/net/matching.c b/src/net/matching.c index a7969506b..e2c7c8ada 100644 --- a/src/net/matching.c +++ b/src/net/matching.c @@ -80,15 +80,16 @@ _z_matching_listener_t _z_matching_listener_declare(_z_session_rc_t *zn, const _ z_result_t _z_matching_listener_entity_undeclare(_z_session_t *zn, _z_zint_t entity_id) { _z_matching_listener_intmap_iterator_t iter = _z_matching_listener_intmap_iterator_make(&zn->_matching_listeners); - while (_z_matching_listener_intmap_iterator_next(&iter)) { + bool has_next = _z_matching_listener_intmap_iterator_next(&iter); + while (has_next) { size_t key = _z_matching_listener_intmap_iterator_key(&iter); _z_matching_listener_state_t *listener = _z_matching_listener_intmap_iterator_value(&iter); + has_next = _z_matching_listener_intmap_iterator_next(&iter); if (listener->entity_id == entity_id) { _Z_DEBUG("_z_matching_listener_entity_undeclare: entity=%i, listener=%i", (int)entity_id, (int)key); - _z_matching_listener_intmap_remove(&zn->_matching_listeners, key); _z_remove_interest(zn, listener->interest_id); + _z_matching_listener_intmap_remove(&zn->_matching_listeners, key); } - _z_str_intmap_iterator_next(&iter); } return _Z_RES_OK; } diff --git a/tests/z_collections_test.c b/tests/z_collections_test.c index 69183050b..c49121569 100644 --- a/tests/z_collections_test.c +++ b/tests/z_collections_test.c @@ -361,12 +361,13 @@ void int_map_iterator_deletion_test(void) { _z_str_intmap_insert(&map, 40, _z_str_clone("D")); _z_str_intmap_iterator_t iter = _z_str_intmap_iterator_make(&map); + _z_str_intmap_iterator_next(&iter); for (size_t s = 4; s != 0; s--) { assert(s == _z_str_intmap_len(&map)); - _z_str_intmap_iterator_next(&iter); size_t key = _z_str_intmap_iterator_key(&iter); assert(strlen(_z_str_intmap_iterator_value(&iter)) == 1); _z_str_intmap_remove(&map, key); + _z_str_intmap_iterator_next(&iter); } _z_str_intmap_clear(&map); }