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

Side by Side Diff: webrtc/modules/video_coding/packet_buffer.cc

Issue 2535203002: Fix memory leak in video_coding::PacketBuffer::InsertPacket. (Closed)
Patch Set: Fixed ownership Created 4 years 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 RTC_DCHECK_LE(start_buffer_size, max_buffer_size); 49 RTC_DCHECK_LE(start_buffer_size, max_buffer_size);
50 // Buffer size must always be a power of 2. 50 // Buffer size must always be a power of 2.
51 RTC_DCHECK((start_buffer_size & (start_buffer_size - 1)) == 0); 51 RTC_DCHECK((start_buffer_size & (start_buffer_size - 1)) == 0);
52 RTC_DCHECK((max_buffer_size & (max_buffer_size - 1)) == 0); 52 RTC_DCHECK((max_buffer_size & (max_buffer_size - 1)) == 0);
53 } 53 }
54 54
55 PacketBuffer::~PacketBuffer() { 55 PacketBuffer::~PacketBuffer() {
56 Clear(); 56 Clear();
57 } 57 }
58 58
59 bool PacketBuffer::InsertPacket(const VCMPacket& packet) { 59 bool PacketBuffer::InsertPacket(VCMPacket* packet) {
60 std::vector<std::unique_ptr<RtpFrameObject>> found_frames; 60 std::vector<std::unique_ptr<RtpFrameObject>> found_frames;
61 { 61 {
62 rtc::CritScope lock(&crit_); 62 rtc::CritScope lock(&crit_);
63 uint16_t seq_num = packet.seqNum; 63 uint16_t seq_num = packet->seqNum;
64 size_t index = seq_num % size_; 64 size_t index = seq_num % size_;
65 65
66 if (!first_packet_received_) { 66 if (!first_packet_received_) {
67 first_seq_num_ = seq_num; 67 first_seq_num_ = seq_num;
68 last_seq_num_ = seq_num; 68 last_seq_num_ = seq_num;
69 first_packet_received_ = true; 69 first_packet_received_ = true;
70 } else if (AheadOf(first_seq_num_, seq_num)) { 70 } else if (AheadOf(first_seq_num_, seq_num)) {
71 // If we have explicitly cleared past this packet then it's old, 71 // If we have explicitly cleared past this packet then it's old,
72 // don't insert it. 72 // don't insert it.
73 if (is_cleared_to_first_seq_num_) 73 if (is_cleared_to_first_seq_num_) {
74 delete[] packet->dataPtr;
74 return false; 75 return false;
76 }
75 77
76 first_seq_num_ = seq_num; 78 first_seq_num_ = seq_num;
77 } 79 }
78 80
79 if (sequence_buffer_[index].used) { 81 if (sequence_buffer_[index].used) {
80 // Duplicate packet, do nothing. 82 // Duplicate packet, just delete the payload.
81 if (data_buffer_[index].seqNum == packet.seqNum) 83 if (data_buffer_[index].seqNum == packet->seqNum) {
84 delete[] packet->dataPtr;
82 return true; 85 return true;
86 }
83 87
84 // The packet buffer is full, try to expand the buffer. 88 // The packet buffer is full, try to expand the buffer.
85 while (ExpandBufferSize() && sequence_buffer_[seq_num % size_].used) { 89 while (ExpandBufferSize() && sequence_buffer_[seq_num % size_].used) {
86 } 90 }
87 index = seq_num % size_; 91 index = seq_num % size_;
88 92
89 // Packet buffer is still full. 93 // Packet buffer is still full.
90 if (sequence_buffer_[index].used) 94 if (sequence_buffer_[index].used) {
95 delete[] packet->dataPtr;
91 return false; 96 return false;
97 }
92 } 98 }
93 99
94 if (AheadOf(seq_num, last_seq_num_)) 100 if (AheadOf(seq_num, last_seq_num_))
95 last_seq_num_ = seq_num; 101 last_seq_num_ = seq_num;
96 102
97 sequence_buffer_[index].frame_begin = packet.isFirstPacket; 103 sequence_buffer_[index].frame_begin = packet->isFirstPacket;
98 sequence_buffer_[index].frame_end = packet.markerBit; 104 sequence_buffer_[index].frame_end = packet->markerBit;
99 sequence_buffer_[index].seq_num = packet.seqNum; 105 sequence_buffer_[index].seq_num = packet->seqNum;
100 sequence_buffer_[index].continuous = false; 106 sequence_buffer_[index].continuous = false;
101 sequence_buffer_[index].frame_created = false; 107 sequence_buffer_[index].frame_created = false;
102 sequence_buffer_[index].used = true; 108 sequence_buffer_[index].used = true;
103 data_buffer_[index] = packet; 109 data_buffer_[index] = *packet;
104 110
105 found_frames = FindFrames(seq_num); 111 found_frames = FindFrames(seq_num);
106 } 112 }
107 113
108 for (std::unique_ptr<RtpFrameObject>& frame : found_frames) 114 for (std::unique_ptr<RtpFrameObject>& frame : found_frames)
109 received_frame_callback_->OnReceivedFrame(std::move(frame)); 115 received_frame_callback_->OnReceivedFrame(std::move(frame));
110 116
111 return true; 117 return true;
112 } 118 }
113 119
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 int PacketBuffer::Release() const { 289 int PacketBuffer::Release() const {
284 int count = rtc::AtomicOps::Decrement(&ref_count_); 290 int count = rtc::AtomicOps::Decrement(&ref_count_);
285 if (!count) { 291 if (!count) {
286 delete this; 292 delete this;
287 } 293 }
288 return count; 294 return count;
289 } 295 }
290 296
291 } // namespace video_coding 297 } // namespace video_coding
292 } // namespace webrtc 298 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698