fix: fixed memory leak and potential use-after-free bug with voiceconn#687
Merged
braindigitalis merged 1 commit intobrainboxdotcc:devfrom May 14, 2023
Merged
Conversation
✅ Deploy Preview for dpp-dev ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Contributor
|
is the pointer now freed by removal of the iterator from the map? |
Member
Author
|
Pretty much, or when the map gets destroyed. The map owns the pointer, and when one of its elements is destroyed, the voiceconn is also destroyed and freed. I didn't find any other code that made use of that map in a modifying way e.g. grabbed/changed the pointer, so this change should be fine. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.