Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed memory leak and potential use-after-free bug with voiceconn #687

Merged
merged 1 commit into from
May 14, 2023

Conversation

Mishura4
Copy link
Member

@Mishura4 Mishura4 commented May 14, 2023

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.

@netlify
Copy link

netlify bot commented May 14, 2023

Deploy Preview for dpp-dev ready!

Name Link
🔨 Latest commit 527a4e1
🔍 Latest deploy log https://app.netlify.com/sites/dpp-dev/deploys/646108a40a63ce0008c7e0c4
😎 Deploy Preview https://deploy-preview-687--dpp-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@braindigitalis
Copy link
Contributor

is the pointer now freed by removal of the iterator from the map?

@Mishura4
Copy link
Member Author

Mishura4 commented May 14, 2023

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.

@braindigitalis braindigitalis merged commit be25004 into brainboxdotcc:dev May 14, 2023
@Mishura4 Mishura4 deleted the voiceconn_leak_crash_fix branch May 14, 2023 16:35
@Commandserver Commandserver added the enhancement New feature or request label Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants