https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124330
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:62bbc98748abc91171872dcf43709975c42d620a commit r16-7897-g62bbc98748abc91171872dcf43709975c42d620a Author: Jakub Jelinek <[email protected]> Date: Wed Mar 4 17:12:29 2026 +0100 libgfortran: Fix up putenv uses in libcaf_shmem [PR124330] I don't have access to HP/UX, but at least on other OSes and what Linux as well as POSIX documents is that when you call putenv with some argument, what that argument points to becomes part of the environment and when it is changed, the environment changes. I believe ENOMEM from putenv is about reallocating of the __environ (or similar) pointed array of pointers (e.g. if the particular env var name isn't there already), it still shouldn't allocate any memory for the NAME=VALUE string and just use the user provided. So, padding address of automatic array will be UB as soon as the scope of that var is left. One can either malloc the buffer, or use static vars, then nothing leaks and in the unlikely case putenv would be called twice for the same env var, it would second time only register the same buffer. 2026-03-04 Jakub Jelinek <[email protected]> PR libfortran/124330 * caf/shmem/shared_memory.c (shared_memory_set_env): Make buffer used by putenv static. (shared_memory_init): Likewise.
