From 3e02430587370ba7e02cd6eec4970fdd6e1ea2c2 Mon Sep 17 00:00:00 2001 From: Honghai Zhang Date: Thu, 22 Sep 2016 09:52:16 -0700 Subject: [PATCH] Fix a stun attribute leak. In https://cs.chromium.org/chromium/src/third_party/webrtc/p2p/base/stun.cc?rcl=1474384719&l=352, if read returned false, the created attr would not be released. BUG=chromium:648064 R=skvlad@webrtc.org Review URL: https://codereview.webrtc.org/2357733002 . Cr-Commit-Position: refs/heads/master@{#14357} --- webrtc/p2p/base/stun.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/webrtc/p2p/base/stun.cc b/webrtc/p2p/base/stun.cc index 78b188afef..658984a643 100644 --- a/webrtc/p2p/base/stun.cc +++ b/webrtc/p2p/base/stun.cc @@ -340,7 +340,8 @@ bool StunMessage::Read(ByteBufferReader* buf) { if (!buf->ReadUInt16(&attr_length)) return false; - StunAttribute* attr = CreateAttribute(attr_type, attr_length); + std::unique_ptr attr( + CreateAttribute(attr_type, attr_length)); if (!attr) { // Skip any unknown or malformed attributes. if ((attr_length % 4) != 0) { @@ -351,7 +352,8 @@ bool StunMessage::Read(ByteBufferReader* buf) { } else { if (!attr->Read(buf)) return false; - attrs_->push_back(attr); + // TODO(honghaiz): Change |attrs_| to be a vector of unique_ptrs. + attrs_->push_back(attr.release()); } }