[flang-commits] [flang] bf53645 - [flang][runtime] Fixed memory leak in Assign().

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Mon May 15 10:48:55 PDT 2023


Author: Slava Zakharin
Date: 2023-05-15T10:48:46-07:00
New Revision: bf536456343ed13249ca251ab564861c920a7615

URL: https://github.com/llvm/llvm-project/commit/bf536456343ed13249ca251ab564861c920a7615
DIFF: https://github.com/llvm/llvm-project/commit/bf536456343ed13249ca251ab564861c920a7615.diff

LOG: [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

Added: 
    

Modified: 
    flang/runtime/assign.cpp

Removed: 
    


################################################################################
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()};


        


More information about the flang-commits mailing list