rtc::ZeroOnFreeBuffer: Don't forget to zero memory we free in operator=

Bug: webrtc:9857
Change-Id: I279e8ea6da4fb9a71e501c0ce01f70e9ebec8c84
Reviewed-on: https://webrtc-review.googlesource.com/c/105042
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25245}
This commit is contained in:
Karl Wiberg 2018-10-10 12:52:17 +02:00 committed by Commit Bot
parent b5541a0023
commit 9d24795ef3

View File

@ -150,6 +150,7 @@ class BufferT {
BufferT& operator=(BufferT&& buf) {
RTC_DCHECK(buf.IsConsistent());
MaybeZeroCompleteBuffer();
size_ = buf.size_;
capacity_ = buf.capacity_;
using std::swap;
@ -375,10 +376,10 @@ class BufferT {
// Zero the complete buffer if template argument "ZeroOnFree" is true.
void MaybeZeroCompleteBuffer() {
if (ZeroOnFree && capacity_) {
if (ZeroOnFree && capacity_ > 0) {
// It would be sufficient to only zero "size_" elements, as all other
// methods already ensure that the unused capacity contains no sensitive
// data - but better safe than sorry.
// data---but better safe than sorry.
ExplicitZeroMemory(data_.get(), capacity_ * sizeof(T));
}
}