summaryrefslogtreecommitdiff
path: root/flang
diff options
context:
space:
mode:
authorSlava Zakharin <szakharin@nvidia.com>2023-05-15 09:52:14 -0700
committerSlava Zakharin <szakharin@nvidia.com>2023-05-15 10:48:46 -0700
commitbf536456343ed13249ca251ab564861c920a7615 (patch)
treef64ab99c18eaa3075487b49188d666dd96d33d80 /flang
parent7c7ffa7bab7e5a67cc3157c66fa5570719043ab3 (diff)
downloadllvm-bf536456343ed13249ca251ab564861c920a7615.tar.gz
[flang][runtime] Fixed memory leak in Assign().
The temporary descriptor must be either Pointer or Allocatable, otherwise its memory will not be freed. Reviewed By: klausler Differential Revision: https://reviews.llvm.org/D150534
Diffstat (limited to 'flang')
-rw-r--r--flang/runtime/assign.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/flang/runtime/assign.cpp b/flang/runtime/assign.cpp
index 9e10e2f491ed..f75fe94bf300 100644
--- a/flang/runtime/assign.cpp
+++ b/flang/runtime/assign.cpp
@@ -294,6 +294,10 @@ static void Assign(
StaticDescriptor<maxRank, true, 16> staticDesc;
Descriptor &newFrom{staticDesc.descriptor()};
std::memcpy(&newFrom, &from, descBytes);
+ // Pretend the temporary descriptor is for an ALLOCATABLE
+ // entity, otherwise, the Deallocate() below will not
+ // free the descriptor memory.
+ newFrom.raw().attribute = CFI_attribute_allocatable;
auto stat{ReturnError(terminator, newFrom.Allocate())};
if (stat == StatOk) {
char *toAt{newFrom.OffsetElement()};