Add limitations of number of frames that can be created in I420BufferPool::CreateBuffer.

If more than 60 frames are created and not returned, the implementation will crash.

I420BufferPool are currently used by the VP8 decoder, Quality scaler and VideoFrameFactory.

BUG=b/31390397
NOTRY=true  // Because of failing gclient runhooks on some bots

Review-Url: https://codereview.webrtc.org/2370653003
Cr-Commit-Position: refs/heads/master@{#14395}
This commit is contained in:
perkj 2016-09-27 03:47:41 -07:00 committed by Commit bot
parent c8299f9f87
commit 5f8ebaeffd
2 changed files with 7 additions and 0 deletions

View File

@ -14,6 +14,8 @@
namespace webrtc {
const size_t I420BufferPool::kMaxNumberOfFramesBeforeCrash = 300;
I420BufferPool::I420BufferPool(bool zero_initialize)
: zero_initialize_(zero_initialize) {}
@ -24,6 +26,8 @@ void I420BufferPool::Release() {
rtc::scoped_refptr<I420Buffer> I420BufferPool::CreateBuffer(int width,
int height) {
RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
RTC_CHECK_LT(buffers_.size(), kMaxNumberOfFramesBeforeCrash)
<< "I420BufferPool too big.";
// Release buffers with wrong resolution.
for (auto it = buffers_.begin(); it != buffers_.end();) {
if ((*it)->width() != width || (*it)->height() != height)

View File

@ -23,6 +23,8 @@ namespace webrtc {
// When the I420Buffer is destructed, the memory is returned to the pool for use
// by subsequent calls to CreateBuffer. If the resolution passed to CreateBuffer
// changes, old buffers will be purged from the pool.
// Note that CreateBuffer will crash if more than kMaxNumberOfFramesBeforeCrash
// are created. This is to prevent memory leaks where frames are not returned.
class I420BufferPool {
public:
I420BufferPool() : I420BufferPool(false) {}
@ -36,6 +38,7 @@ class I420BufferPool {
void Release();
private:
static const size_t kMaxNumberOfFramesBeforeCrash;
// Explicitly use a RefCountedObject to get access to HasOneRef,
// needed by the pool to check exclusive access.
using PooledI420Buffer = rtc::RefCountedObject<I420Buffer>;