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

libgfortran: Fix shared memory object leak in caf_shmem

Fixes a shared memory object leak in libgfortran's `caf_shmem` when the supervisor process is signaled.

This commit resolves a shared memory object leak in libgfortran’s caf_shmem component. Previously, if the supervisor process terminated due to a signal (like Ctrl+C or a timeout), it would exit without unlinking the shared memory object, leaving it behind. The fix ensures the shared memory object is properly unlinked after its descriptor is passed to child processes, preventing resource leaks and excluding the mapping from core dumps.

In Details

This commit addresses PR libfortran/127753 by modifying libgfortran/caf/shmem/shared_memory.c. Previously, upon receiving a signal, the supervisor process would exit without unlinking the shared memory object. The change introduces ENV_FD to pass the file descriptor to child processes and immediately unlinks the shared memory object name. This ensures the object is cleaned up when the last process using it terminates. Additionally, the mapping is excluded from core dumps to prevent writing unlinked objects.

For Context
libgfortran
The GNU Fortran runtime library, providing support for Fortran programs compiled by GCC.
caf_shmem
A component within libgfortran that likely handles shared memory mechanisms for Fortran's Co-Array Fortran (CAF) feature.
shared memory object
A region of memory that can be accessed by multiple processes. On POSIX systems, these are often implemented using file-backed mechanisms (e.g., in /dev/shm).
supervisor process
In this context, a process that manages or initiates other processes, likely related to distributed or parallel execution in Co-Array Fortran.
unlink
In file system terms, removing a name (link) that points to a file. When the last link is removed and no process has the file open, the file's data is deallocated.
core dump
A file containing a snapshot of a process's memory at the time it terminated abnormally, used for debugging.
Filed Under: libgfortranshared memoryresource leakCo-Array Fortran