Skip to content

Commit

Permalink
Fix MSAN use-after-free in SmallVectorImpl dtor (#6819)
Browse files Browse the repository at this point in the history
Hit when compiled with `-fsanitize-memory-use-after-dtor`. This was
fixed upstream here:

llvm/llvm-project@527352b
This applies the same patch.
  • Loading branch information
amaiorano authored Jul 26, 2024
1 parent 0777bff commit ef4f44d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions include/llvm/ADT/SmallVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T, isPodLike<T>::value> {

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

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

~SmallVector() {
// Destroy the constructed elements in the vector.
this->destroy_range(this->begin(), this->end());
}

explicit SmallVector(size_t Size, const T &Value = T())
: SmallVectorImpl<T>(N) {
this->assign(Size, Value);
Expand Down

0 comments on commit ef4f44d

Please sign in to comment.