Unverified 提交 fab4891c authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Worker: Fix possible double free when ICE consent check fails (#1393)

上级 ea40829a
# Changelog
### NEXT
- Worker: Fix possible double free when ICE consent check fails ([PR #1393](https://github.com/versatica/mediasoup/pull/1393)).
### 3.14.5
- Worker: Fix memory leak when using `WebRtcServer` with TCP enabled ([PR #1389](https://github.com/versatica/mediasoup/pull/1389)).
......
......@@ -131,7 +131,6 @@ namespace RTC
std::string password;
uint16_t consentTimeoutMs{ 30000u };
// Others.
bool destroying{ false };
std::string oldUsernameFragment;
std::string oldPassword;
IceState state{ IceState::NEW };
......@@ -140,6 +139,7 @@ namespace RTC
RTC::TransportTuple* selectedTuple{ nullptr };
TimerHandle* consentCheckTimer{ nullptr };
uint64_t lastConsentRequestReceivedAtMs{ 0u };
bool isRemovingTuples{ false };
};
} // namespace RTC
......
......@@ -112,8 +112,6 @@ namespace RTC
{
MS_TRACE();
this->destroying = true;
// Here we must notify the listener about the removal of current
// usernameFragments (and also the old one if any) and all tuples.
......@@ -125,6 +123,8 @@ namespace RTC
}
// Clear all tuples.
this->isRemovingTuples = true;
for (const auto& it : this->tuples)
{
auto* storedTuple = const_cast<RTC::TransportTuple*>(std::addressof(it));
......@@ -133,6 +133,8 @@ namespace RTC
this->listener->OnIceServerTupleRemoved(this, storedTuple);
}
this->isRemovingTuples = false;
// Clear all tuples.
// NOTE: Do it after notifying the listener since the listener may need to
// use/read the tuple being removed so we cannot free it yet.
......@@ -225,9 +227,10 @@ namespace RTC
{
MS_TRACE();
// While IceServer is being destroyed, it may call listener methods that may
// end calling RemoveTuple(). We must ignore it to avoid double-free issues.
if (this->destroying)
// If IceServer is removing a tuple or all tuples (for instance in the
// destructor), the OnIceServerTupleRemoved() callback may end triggering
// new calls to RemoveTuple(). We must ignore it to avoid double-free issues.
if (this->isRemovingTuples)
{
return;
}
......@@ -256,7 +259,9 @@ namespace RTC
}
// Notify the listener.
this->isRemovingTuples = true;
this->listener->OnIceServerTupleRemoved(this, removedTuple);
this->isRemovingTuples = false;
// Remove it from the list of tuples.
// NOTE: Do it after notifying the listener since the listener may need to
......@@ -810,7 +815,9 @@ namespace RTC
MS_ASSERT(removedTuple, "couldn't find any tuple to be removed");
// Notify the listener.
this->isRemovingTuples = true;
this->listener->OnIceServerTupleRemoved(this, removedTuple);
this->isRemovingTuples = false;
// Remove it from the list of tuples.
// NOTE: Do it after notifying the listener since the listener may need to
......@@ -927,6 +934,8 @@ namespace RTC
this->remoteNomination = 0u;
// Clear all tuples.
this->isRemovingTuples = true;
for (const auto& it : this->tuples)
{
auto* storedTuple = const_cast<RTC::TransportTuple*>(std::addressof(it));
......@@ -935,6 +944,8 @@ namespace RTC
this->listener->OnIceServerTupleRemoved(this, storedTuple);
}
this->isRemovingTuples = false;
// Clear all tuples.
// NOTE: Do it after notifying the listener since the listener may need to
// use/read the tuple being removed so we cannot free it yet.
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论