The master branch has been updated by Jerry DeLisle <[email protected]>:
https://gcc.gnu.org/g:e002a4e17481c1a083e2b49374565dbb2621aef8
commit r17-1552-ge002a4e17481c1a083e2b49374565dbb2621aef8
Author: Jerry DeLisle <[email protected]>
Date: Sat Jun 13 19:10:04 2026 -0700
fortran: Fix double free in ASSOCIATE over allocatable char function
[PR125782]
On 6/14/26 12:04 PM, Jerry D wrote:
See attached.
I plan to commit this as obvious/simple.
Regression tested on X86_64
Best regards
Jerry
Author: Jerry DeLisle <[email protected]>
Date: Sat Jun 13 19:10:04 2026 -0700
fortran: Fix double free for ASSOCIATE over allocatable character function
[PR125782]
When an ASSOCIATE selector is a function call returning an allocatable
deferred-length character, trans_associate_var unconditionally added an
extra free of the associate-name's backend decl. That free was added in
2017 (PR60458/77296) to release the result of a POINTER-valued character
function, which is not otherwise freed. For an ALLOCATABLE-valued
character function, however, the result temporary is already freed by the
procedure call's own cleanup code, and the associate name aliases that
same temporary, so the extra free caused a double free at the end of the
ASSOCIATE block.
Restrict the extra free to POINTER-valued function results, where it is
still needed.
Assisted by: Claude Sonnet 4.6
PR fortran/125782
gcc/fortran/ChangeLog:
* trans-stmt.cc (trans_associate_var): Only free the associate
name's backend decl for a deferred-length character function
result when the result is a POINTER, not when it is
ALLOCATABLE, since the latter is already freed by the
procedure call's cleanup.
gcc/testsuite/ChangeLog:
* gfortran.dg/associate_82.f90: New test.