https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127941
--- Comment #4 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:1fe80b2edf859d7bc66207d32d7ba1213f406799 commit r17-5275-g1fe80b2edf859d7bc66207d32d7ba1213f406799 Author: Jerry DeLisle <[email protected]> Date: Fri Oct 16 11:14:56 2026 -0700 fortran: [PR127941] Fix invalid free in CLASS finalization wrapper Deallocating a CLASS object whose type has a non-allocatable derived type array component with nested allocatable components freed an invalid pointer. For such a component the finalization wrapper deallocates an expression like ptr%entries(:)%children, and gfc_trans_deallocate already handles that form by deallocating the allocatable components of the array elements. It also ran the generic allocatable-component cleanup with the type of the last component, which applied that type's components to the array elements. The patch skips the generic cleanup for this form. Assisted-by: Claude Opus 5.5 PR fortran/127941 gcc/fortran/ChangeLog: * trans-stmt.cc (gfc_trans_deallocate): Do not deallocate the allocatable components of the last component's type when the expression is a non-allocatable array component generated by finalize_component. gcc/testsuite/ChangeLog: * gfortran.dg/allocate_with_source_14.f03: Expect one fewer call to __builtin_free. * gfortran.dg/finalize_64.f90: New test.
