Skip to content
New issue

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

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

Already on GitHub? # 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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/dpp/discordclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ class DPP_EXPORT discord_client : public websocket_client
/**
* @brief List of voice channels we are connecting to keyed by guild id
*/
std::unordered_map<snowflake, voiceconn*> connecting_voice_channels;
std::unordered_map<snowflake, std::unique_ptr<voiceconn>> connecting_voice_channels;

/**
* @brief The gateway address we reconnect to when we resume a session
Expand Down
6 changes: 2 additions & 4 deletions src/dpp/discordclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ discord_client& discord_client::connect_voice(snowflake guild_id, snowflake chan
#ifdef HAVE_VOICE
std::unique_lock lock(voice_mutex);
if (connecting_voice_channels.find(guild_id) == connecting_voice_channels.end()) {
connecting_voice_channels[guild_id] = new voiceconn(this, channel_id);
connecting_voice_channels[guild_id] = std::make_unique<voiceconn>(this, channel_id);
/* Once sent, this expects two events (in any order) on the websocket:
* VOICE_SERVER_UPDATE and VOICE_STATUS_UPDATE
*/
Expand Down Expand Up @@ -658,8 +658,6 @@ void discord_client::disconnect_voice_internal(snowflake guild_id, bool emit_jso
}
})), false);
}
delete v->second;
v->second = nullptr;
connecting_voice_channels.erase(v);
}
#endif
Expand All @@ -675,7 +673,7 @@ voiceconn* discord_client::get_voice(snowflake guild_id) {
std::shared_lock lock(voice_mutex);
auto v = connecting_voice_channels.find(guild_id);
if (v != connecting_voice_channels.end()) {
return v->second;
return v->second.get();
}
#endif
return nullptr;
Expand Down