https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121972

--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jerry DeLisle <[email protected]>:

https://gcc.gnu.org/g:9579e3eb64ec89c4c0781bb0a59409f15c997213

commit r17-1786-g9579e3eb64ec89c4c0781bb0a59409f15c997213
Author: Jerry DeLisle <[email protected]>
Date:   Fri Jun 19 14:54:00 2026 -0700

    fortran: Fix memory leak for array structure-constructor element [PR121972]

    Fix the remaining leak in pdt_86.f03. Added a new test in asan to avoid it.

            PR fortran/121972

    gcc/fortran/ChangeLog:

            * trans-array.cc (has_class_alloc_comp): New helper; returns true
if
            derived type DER has any CLASS component.
            (gfc_trans_array_ctor_element): Also free allocatable components
when
            the element expression is EXPR_STRUCTURE, skipping types that
contain
            CLASS components to avoid freeing stack-allocated _data pointers.
            (gfc_constructor_is_owned_alloc_comp): Likewise treat
EXPR_STRUCTURE
            elements as owned only when the derived type has no CLASS
components.
            * trans-expr.cc (gfc_trans_alloc_subarray_assign): Free allocatable
            components of the component's temporary descriptor before nulling
its
            data pointer, for non-variable source expressions.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/class_array_15.f03: Adjust expected free count.
            * gfortran.dg/derived_constructor_comps_6.f90: Adjust expected free
count.
            * gfortran.dg/asan/structure_constructor_alloc_comp_leak_1.f90: New
test.

Reply via email to