[all-commits] [llvm/llvm-project] 4affd0: [mlir] fix a memory leak in NestedPattern
ftynse via All-commits
all-commits at lists.llvm.org
Fri Mar 12 09:52:38 PST 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 4affd0c40eccbce921f185e1e09f84f8194cd4cf
https://github.com/llvm/llvm-project/commit/4affd0c40eccbce921f185e1e09f84f8194cd4cf
Author: Alex Zinenko <zinenko at google.com>
Date: 2021-03-12 (Fri, 12 Mar 2021)
Changed paths:
M mlir/include/mlir/Analysis/NestedMatcher.h
M mlir/lib/Analysis/NestedMatcher.cpp
Log Message:
-----------
[mlir] fix a memory leak in NestedPattern
NestedPattern uses a BumpPtrAllocator to store child (nested) pattern
objects to decrease the overhead of dynamic allocation. This assumes all
allocations happen inside the allocator that will be freed as a whole.
However, NestedPattern contains `std::function` as a member, which
allocates internally using `new`, unaware of the BumpPtrAllocator. Since
NestedPattern only holds pointers to the nested patterns allocated in
the BumpPtrAllocator, it never calls their destructors, so the
destructor of the `std::function`s they contain are never called either,
leaking the allocated memory.
Make NestedPattern explicitly call destructors of nested patterns. This
additionally requires to actually copy the nested patterns in
copy-construction and copy-assignment instead of just sharing the
pointer to the arena-allocated list of children to avoid double-free. An
alternative solution would be to add reference counting to the list of
arena-allocated list of children.
Reviewed By: nicolasvasilache
Differential Revision: https://reviews.llvm.org/D98485
More information about the All-commits
mailing list