diff options
author | Slava Zakharin <szakharin@nvidia.com> | 2023-05-15 09:52:14 -0700 |
---|---|---|
committer | Slava Zakharin <szakharin@nvidia.com> | 2023-05-15 10:48:46 -0700 |
commit | bf536456343ed13249ca251ab564861c920a7615 (patch) | |
tree | f64ab99c18eaa3075487b49188d666dd96d33d80 /flang | |
parent | 7c7ffa7bab7e5a67cc3157c66fa5570719043ab3 (diff) | |
download | llvm-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.cpp | 4 |
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()}; |