summaryrefslogtreecommitdiff
path: root/libartbase/base/bit_vector.cc
diff options
context:
space:
mode:
author Alex Light <allight@google.com> 2020-09-17 14:16:36 -0700
committer Alex Light <allight@google.com> 2020-09-18 21:43:11 +0000
commit3c7bd3c783e5a171f7ae1e5bc1c11cb95b80a93b (patch)
tree23d17987145abef47875db7cdbf03e5b8eb276c5 /libartbase/base/bit_vector.cc
parent46c2a23dbbe48c8ba1dd0238e844f9b5fda47ec7 (diff)
Fix issue where moving BitVector could cause free(nullptr)
If one std::move's a BitVector the old BitVector's storage_ will be nulled and size set to 0. This is fine but when ~BitVector is run the allocator will be asked to free a nullptr. Since this is generally not expected by allocators, not supported by some and breaks the movement semantics of C++ I've changed the behavior to only Free memory if there is memory to be freed. Test: ./test.py --host Change-Id: I2716a604370c94bcea1a0989c5e6b94e45a2b063
Diffstat (limited to 'libartbase/base/bit_vector.cc')
-rw-r--r--libartbase/base/bit_vector.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/libartbase/base/bit_vector.cc b/libartbase/base/bit_vector.cc
index b32b4117dd..8e3d4c9bf7 100644
--- a/libartbase/base/bit_vector.cc
+++ b/libartbase/base/bit_vector.cc
@@ -61,7 +61,10 @@ BitVector::BitVector(const BitVector& src,
}
BitVector::~BitVector() {
- allocator_->Free(storage_);
+ if (storage_ != nullptr) {
+ // Only free if we haven't been moved out of.
+ allocator_->Free(storage_);
+ }
}
bool BitVector::SameBitsSet(const BitVector *src) const {