Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Unified Diff: webrtc/p2p/base/turnserver.cc

Issue 2114063002: Fixing memory leak in TurnServer. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Using std::tie, added unit test. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/p2p/base/turnserver.h ('k') | webrtc/p2p/base/turnserver_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/turnserver.cc
diff --git a/webrtc/p2p/base/turnserver.cc b/webrtc/p2p/base/turnserver.cc
index b4510e637fa6c9273342eda4966052fbaf7a5d15..7dd9e19f63d0f9abd5268218d3210d84f01ab33b 100644
--- a/webrtc/p2p/base/turnserver.cc
+++ b/webrtc/p2p/base/turnserver.cc
@@ -10,6 +10,8 @@
#include "webrtc/p2p/base/turnserver.h"
+#include <tuple> // for std::tie
+
#include "webrtc/p2p/base/asyncstuntcpsocket.h"
#include "webrtc/p2p/base/common.h"
#include "webrtc/p2p/base/packetsocketfactory.h"
@@ -124,11 +126,6 @@ TurnServer::TurnServer(rtc::Thread* thread)
}
TurnServer::~TurnServer() {
- for (AllocationMap::iterator it = allocations_.begin();
- it != allocations_.end(); ++it) {
- delete it->second;
- }
-
for (InternalSocketMap::iterator it = server_sockets_.begin();
it != server_sockets_.end(); ++it) {
rtc::AsyncPacketSocket* socket = it->first;
@@ -429,7 +426,7 @@ bool TurnServer::ValidateNonce(const std::string& nonce) const {
TurnServerAllocation* TurnServer::FindAllocation(TurnServerConnection* conn) {
AllocationMap::const_iterator it = allocations_.find(*conn);
- return (it != allocations_.end()) ? it->second : NULL;
+ return (it != allocations_.end()) ? it->second.get() : nullptr;
}
TurnServerAllocation* TurnServer::CreateAllocation(TurnServerConnection* conn,
@@ -445,7 +442,7 @@ TurnServerAllocation* TurnServer::CreateAllocation(TurnServerConnection* conn,
TurnServerAllocation* allocation = new TurnServerAllocation(this,
thread_, *conn, external_socket, key);
allocation->SignalDestroyed.connect(this, &TurnServer::OnAllocationDestroyed);
- allocations_[*conn] = allocation;
+ allocations_[*conn].reset(allocation);
return allocation;
}
@@ -518,8 +515,10 @@ void TurnServer::OnAllocationDestroyed(TurnServerAllocation* allocation) {
}
AllocationMap::iterator it = allocations_.find(*(allocation->conn()));
- if (it != allocations_.end())
+ if (it != allocations_.end()) {
+ it->second.release();
allocations_.erase(it);
+ }
}
void TurnServer::DestroyInternalSocket(rtc::AsyncPacketSocket* socket) {
@@ -547,7 +546,7 @@ bool TurnServerConnection::operator==(const TurnServerConnection& c) const {
}
bool TurnServerConnection::operator<(const TurnServerConnection& c) const {
- return src_ < c.src_ || dst_ < c.dst_ || proto_ < c.proto_;
+ return std::tie(src_, dst_, proto_) < std::tie(c.src_, c.dst_, c.proto_);
}
std::string TurnServerConnection::ToString() const {
« no previous file with comments | « webrtc/p2p/base/turnserver.h ('k') | webrtc/p2p/base/turnserver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698