Skip to content

Commit ed13d8c

Browse files
committed
Fix memory leak complicated non-type template arguments.
1 parent 72d8f79 commit ed13d8c

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,8 +2818,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
28182818
/// for destruction.
28192819
template <typename T> void addDestruction(T *Ptr) const {
28202820
if (!std::is_trivially_destructible<T>::value) {
2821-
auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); };
2822-
AddDeallocation(DestroyPtr, Ptr);
2821+
auto DestroyPtr = [](void *V) { ((T*)V)->~T(); };
2822+
AddDeallocation(DestroyPtr, (void*)Ptr);
28232823
}
28242824
}
28252825

clang/lib/AST/TemplateBase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ TemplateArgument::TemplateArgument(const ASTContext &Ctx, QualType Type,
137137
else {
138138
Value.Kind = UncommonValue;
139139
Value.Value = new (Ctx) APValue(V);
140+
Ctx.addDestruction(Value.Value);
140141
Value.Type = Type.getAsOpaquePtr();
141142
}
142143
}

0 commit comments

Comments
 (0)