Skip to content

Commit

Permalink
srtp_stream_list_for_each: rely on available entries
Browse files Browse the repository at this point in the history
Since this function is used to iterate and remove the entries in the
list, rely on list availability to increase the loop counter.

NOTE: Previously 'ssrc' was checked, but this breaks the case were there
are multiple entries with the same 'ssrc'.
  • Loading branch information
jmillan committed Jan 11, 2024
1 parent 1f23e07 commit 3e0c6ec
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions srtp/srtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4971,7 +4971,7 @@ void srtp_stream_list_for_each(srtp_stream_list_t list,
{
list_entry *entries = list->entries;

uint32_t ssrc;
size_t available = list->available;

/*
* the second statement of the expression needs to be recalculated on each
Expand All @@ -4980,15 +4980,16 @@ void srtp_stream_list_for_each(srtp_stream_list_t list,
* Ie: in case the callback calls srtp_stream_list_remove().
*/
for (unsigned int i = 0; i < list->size - list->available;) {
ssrc = entries[i].ssrc;
if (callback(entries[i].stream, data)) {
break;
}

// the entry was not removed, increase the counter.
if (ssrc == entries[i].ssrc) {
if (available == list->available) {
++i;
}

available = list->available;
}
}

Expand Down

0 comments on commit 3e0c6ec

Please sign in to comment.