GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
fortran

Fortran: Free LEN components of PDTs in CLASS(*) objects

Fixes memory leaks in Fortran by properly deallocating LEN components of polymorphic types.

This change addresses memory leaks in Fortran’s handling of polymorphic types. Previously, the deallocation of objects with LEN-dependent components in PDTs was incomplete, leaving memory unreleased. Additionally, polymorphic assignments from structure constructors caused leaks in their temporary components. The fix ensures these components are finalized and deallocated, resolving issues with memory management for complex polymorphic assignments and structure constructors.

In Details

This commit fixes a memory leak in the Fortran front-end related to the finalization of polymorphic derived types (PDTs). Specifically, it ensures that the LEN components of PDTs, which are dynamically sized, are correctly deallocated when the parent object is finalized. It also addresses leaks from structure constructor temporaries during polymorphic assignment. The fix modifies pdt_len_component, pdt_len_storage_comp, comp_is_finalizable, finalize_component, and generate_finalization_wrapper in class.cc, and gfc_trans_assignment_1 in trans-expr.cc.

Filed Under: fortranmemory leakpolymorphism