Skip to content

Commit ef4f44d

Browse files
authored
Fix MSAN use-after-free in SmallVectorImpl dtor (microsoft#6819)
Hit when compiled with `-fsanitize-memory-use-after-dtor`. This was fixed upstream here: llvm/llvm-project@527352b This applies the same patch.
1 parent 0777bff commit ef4f44d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

include/llvm/ADT/SmallVector.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T, isPodLike<T>::value> {
359359

360360
public:
361361
~SmallVectorImpl() {
362-
// Destroy the constructed elements in the vector.
363-
this->destroy_range(this->begin(), this->end());
362+
// Subclass has already destructed this vector's elements.
364363

365364
// If this wasn't grown from the inline copy, deallocate the old space.
366365
if (!this->isSmall())
@@ -865,6 +864,11 @@ class SmallVector : public SmallVectorImpl<T> {
865864
SmallVector() : SmallVectorImpl<T>(N) {
866865
}
867866

867+
~SmallVector() {
868+
// Destroy the constructed elements in the vector.
869+
this->destroy_range(this->begin(), this->end());
870+
}
871+
868872
explicit SmallVector(size_t Size, const T &Value = T())
869873
: SmallVectorImpl<T>(N) {
870874
this->assign(Size, Value);

0 commit comments

Comments
 (0)