Fix memory leak in video_coding::PacketBuffer::InsertPacket.

BUG=webrtc:6788

Review-Url: https://codereview.webrtc.org/2535203002
Cr-Commit-Position: refs/heads/master@{#15314}
This commit is contained in:
philipel
2016-11-30 01:32:05 -08:00
committed by Commit bot
parent be74270ebe
commit 759e0b7241
5 changed files with 77 additions and 44 deletions

View File

@ -56,11 +56,11 @@ PacketBuffer::~PacketBuffer() {
Clear();
}
bool PacketBuffer::InsertPacket(const VCMPacket& packet) {
bool PacketBuffer::InsertPacket(VCMPacket* packet) {
std::vector<std::unique_ptr<RtpFrameObject>> found_frames;
{
rtc::CritScope lock(&crit_);
uint16_t seq_num = packet.seqNum;
uint16_t seq_num = packet->seqNum;
size_t index = seq_num % size_;
if (!first_packet_received_) {
@ -70,16 +70,22 @@ bool PacketBuffer::InsertPacket(const VCMPacket& packet) {
} else if (AheadOf(first_seq_num_, seq_num)) {
// If we have explicitly cleared past this packet then it's old,
// don't insert it.
if (is_cleared_to_first_seq_num_)
if (is_cleared_to_first_seq_num_) {
delete[] packet->dataPtr;
packet->dataPtr = nullptr;
return false;
}
first_seq_num_ = seq_num;
}
if (sequence_buffer_[index].used) {
// Duplicate packet, do nothing.
if (data_buffer_[index].seqNum == packet.seqNum)
// Duplicate packet, just delete the payload.
if (data_buffer_[index].seqNum == packet->seqNum) {
delete[] packet->dataPtr;
packet->dataPtr = nullptr;
return true;
}
// The packet buffer is full, try to expand the buffer.
while (ExpandBufferSize() && sequence_buffer_[seq_num % size_].used) {
@ -87,20 +93,24 @@ bool PacketBuffer::InsertPacket(const VCMPacket& packet) {
index = seq_num % size_;
// Packet buffer is still full.
if (sequence_buffer_[index].used)
if (sequence_buffer_[index].used) {
delete[] packet->dataPtr;
packet->dataPtr = nullptr;
return false;
}
}
if (AheadOf(seq_num, last_seq_num_))
last_seq_num_ = seq_num;
sequence_buffer_[index].frame_begin = packet.isFirstPacket;
sequence_buffer_[index].frame_end = packet.markerBit;
sequence_buffer_[index].seq_num = packet.seqNum;
sequence_buffer_[index].frame_begin = packet->isFirstPacket;
sequence_buffer_[index].frame_end = packet->markerBit;
sequence_buffer_[index].seq_num = packet->seqNum;
sequence_buffer_[index].continuous = false;
sequence_buffer_[index].frame_created = false;
sequence_buffer_[index].used = true;
data_buffer_[index] = packet;
data_buffer_[index] = *packet;
packet->dataPtr = nullptr;
found_frames = FindFrames(seq_num);
}