Use HasOneRef to ensure safe reallocation of buffer in EncodedImage
If somehow buffer is shared between other locations, reallocating it may lead to use-after-free error. Bug: none Change-Id: I01a0b722cfe6ee0e18546248f1dfb7b8ac3b7217 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/150884 Reviewed-by: Niels Moller <nisse@webrtc.org> Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29021}
This commit is contained in:
committed by
Commit Bot
parent
f13df86414
commit
ddd50ef921
@ -77,7 +77,7 @@ void EncodedImage::Retain() {
|
||||
}
|
||||
|
||||
void EncodedImage::Allocate(size_t capacity) {
|
||||
if (encoded_data_) {
|
||||
if (encoded_data_ && encoded_data_->HasOneRef()) {
|
||||
encoded_data_->Realloc(capacity);
|
||||
} else {
|
||||
encoded_data_ = EncodedImageBuffer::Create(capacity);
|
||||
|
||||
@ -47,6 +47,9 @@ class EncodedImageBufferInterface : public rtc::RefCountInterface {
|
||||
// EncodedImage::Allocate. Implemented properly only by the below concrete
|
||||
// class
|
||||
virtual void Realloc(size_t size) { RTC_NOTREACHED(); }
|
||||
// Will be implemented by RefCountedObject, which also implements
|
||||
// |rtc::RefCountInterface|.
|
||||
virtual bool HasOneRef() const = 0;
|
||||
};
|
||||
|
||||
// Basic implementation of EncodedImageBufferInterface.
|
||||
|
||||
Reference in New Issue
Block a user