diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index 9d6188f8a0..c70e0f9a65 100755 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -3597,6 +3597,8 @@ SWITCH_STANDARD_API(ft_function) { char *mycmd = NULL, *argv[10] = { 0 }; int argc = 0; + ftdm_iterator_t *chaniter = NULL; + ftdm_iterator_t *curr = NULL; if (!zstr(cmd) && (mycmd = strdup(cmd))) { argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); @@ -3642,11 +3644,11 @@ SWITCH_STANDARD_API(ft_function) dump_chan_xml(span, chan_id, stream); } } else { - uint32_t j; - uint32_t ccount = ftdm_span_get_chan_count(span); - for (j = 1; j <= ccount; j++) { - dump_chan_xml(span, j, stream); + chaniter = ftdm_span_get_chan_iterator(span, NULL); + for (curr = chaniter; curr; curr = ftdm_iterator_next(curr)) { + dump_chan_xml(span, ftdm_channel_get_id(ftdm_iterator_current(curr)), stream); } + ftdm_iterator_free(chaniter); } } @@ -3662,12 +3664,12 @@ SWITCH_STANDARD_API(ft_function) dump_chan(span, chan_id, stream); } } else { - uint32_t j; - uint32_t ccount = ftdm_span_get_chan_count(span); stream->write_function(stream, "+OK\n"); - for (j = 1; j <= ccount; j++) { - dump_chan(span, j, stream); + chaniter = ftdm_span_get_chan_iterator(span, NULL); + for (curr = chaniter; curr; curr = ftdm_iterator_next(curr)) { + dump_chan(span, ftdm_channel_get_id(ftdm_iterator_current(curr)), stream); } + ftdm_iterator_free(chaniter); } } diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index b83f1b7e88..c774e61901 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -3602,9 +3602,8 @@ FT_DECLARE(ftdm_iterator_t *) ftdm_iterator_next(ftdm_iterator_t *iter) } return iter; case FTDM_ITERATOR_CHANS: - if (iter->pvt.chaniter.index == iter->pvt.chaniter.span->chan_count) { - return NULL; - } + ftdm_assert_return(iter->pvt.chaniter.index, NULL, "channel iterator index cannot be zero!\n"); + ftdm_assert_return(iter->pvt.chaniter.index <= iter->pvt.chaniter.span->chan_count, NULL, "channel iterator index bigger than span chan count!\n"); iter->pvt.chaniter.index++; return iter; default: @@ -3629,7 +3628,7 @@ FT_DECLARE(void *) ftdm_iterator_current(ftdm_iterator_t *iter) return (void *)key; case FTDM_ITERATOR_CHANS: ftdm_assert_return(iter->pvt.chaniter.index, NULL, "channel iterator index cannot be zero!\n"); - ftdm_assert_return(iter->pvt.chaniter.index > iter->pvt.chaniter.span->chan_count, NULL, "channel iterator index bigger than span chan count!\n"); + ftdm_assert_return(iter->pvt.chaniter.index <= iter->pvt.chaniter.span->chan_count, NULL, "channel iterator index bigger than span chan count!\n"); return iter->pvt.chaniter.span->channels[iter->pvt.chaniter.index]; default: break; @@ -3652,6 +3651,7 @@ FT_DECLARE(ftdm_status_t) ftdm_iterator_free(ftdm_iterator_t *iter) } ftdm_assert_return(iter->type, FTDM_FAIL, "Cannot free invalid iterator\n"); + ftdm_log(FTDM_LOG_DEBUG, "Freeing iterator %p\n", iter); ftdm_safe_free(iter); return FTDM_SUCCESS;