Skip to content

Commit bf53645

Browse files
committed
[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
1 parent 7c7ffa7 commit bf53645

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

flang/runtime/assign.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ static void Assign(
294294
StaticDescriptor<maxRank, true, 16> staticDesc;
295295
Descriptor &newFrom{staticDesc.descriptor()};
296296
std::memcpy(&newFrom, &from, descBytes);
297+
// Pretend the temporary descriptor is for an ALLOCATABLE
298+
// entity, otherwise, the Deallocate() below will not
299+
// free the descriptor memory.
300+
newFrom.raw().attribute = CFI_attribute_allocatable;
297301
auto stat{ReturnError(terminator, newFrom.Allocate())};
298302
if (stat == StatOk) {
299303
char *toAt{newFrom.OffsetElement()};

0 commit comments

Comments
 (0)