OpenWebTorrent / openwebtorrent-tracker

Fast and simple Webtorrent tracker implementation in C++
https://openwebtorrent.com
71 stars 22 forks source link

Fix deletion of infohashes in disconnectPeer #20

Closed theawless closed 3 years ago

theawless commented 3 years ago

We should not delete items from the container during a ranged for loop. This commit utilises the pointer returned by container erase.

Reference https://stackoverflow.com/questions/51744166 Fixes https://github.com/OpenWebTorrent/openwebtorrent-tracker/issues/19

theawless commented 3 years ago

Now that I think about it, we probably don't need to play with iterators at all. After cleaning up the swarms, we just need to clear() the infoHashes set at the end.

Please let me know if that would be preferable, then I'll raise a new revision.

alxhotel commented 3 years ago

Now that I think about it, we probably don't need to play with iterators at all. After cleaning up the swarms, we just need to clear() the infoHashes set at the end.

Please let me know if that would be preferable, then I'll raise a new revision.

Thanks @theawless. This PR is great!

If you want you can rewrite it with your suggestion. I think that approach will be cleaner.