fix: fixed memory leak and potential use-after-free bug with voiceconn #687
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
dpp::discord_voice_client does not free its active voice connections on destruction. This means that, when the cluster/voice client gets destroyed, any dpp::voiceconn objects as well as threads they have running won't be joined or freed. This causes not only a memory leak, but in the event of the cluster/voice client getting destroyed, and the still alive voiceconn thread trying to for example log a message, a use-after-free will occur and cause undefined behavior (usually a crash). This has happened to me about on about 50% of my executions of the unit tests on Windows.
This PR fixes this bug. However it does make use of std::unique_ptr, that as I understand it the library does not usually use, let me know if you would like me to change it to new/delete instead.