Skip to content

Commit

Permalink
Fix segfault when removing elements from tracks
Browse files Browse the repository at this point in the history
Signed-off-by: tempate <[email protected]>
  • Loading branch information
Tempate committed Sep 20, 2023
1 parent 5c8c214 commit d17a953
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ddspipe_core/src/cpp/communication/dds/DdsBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,19 @@ void DdsBridge::add_to_tracks(
void DdsBridge::remove_from_tracks(
const ParticipantId& discoverer_participant_id) noexcept
{
for (const auto& id_to_track : tracks_)
for (auto it = tracks_.cbegin(), next_it = it; it != tracks_.cend(); it = next_it)
{
const auto& id = id_to_track.first;
const auto& track = id_to_track.second;
++next_it;

const auto& track = it->second;

// If the writer is in the track, remove it.
track->remove_writer(discoverer_participant_id);

if (track->count_writers() <= 0)
{
// The track doesn't have any writers. Remove it.
tracks_.erase(id);
tracks_.erase(it);
}
}
}
Expand Down

0 comments on commit d17a953

Please sign in to comment.