GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libfortran

Libfortran: Fixed static analyzer warning in free_format_data.

Addresses a cppcheck warning by changing the argument to free_format_data to pass a pointer to a pointer.

A static analysis tool, cppcheck, reported a pointless assignment in the free_format_data function. The function was intended to nullify a pointer after freeing the memory it pointed to, but this wasn’t effective in C because arguments are passed by value. This commit changes the function to accept a pointer to a pointer, allowing it to nullify the original pointer. This resolves the static analyzer warning.

In Details

The free_format_data function in libgfortran/io/format.c is responsible for freeing memory associated with format data. The original code attempted to nullify the pointer after freeing the memory, but C's pass-by-value semantics prevented this. The fix changes the function signature to accept a format_data**, enabling the function to modify the original pointer. The callers free_format_hash_table, save_parsed_format, st_read_done_worker, and st_write_done_worker are updated accordingly.

For Context

Static analysis tools help detect potential errors in code without running the program. This commit addresses a warning reported by such a tool (cppcheck) in the Fortran runtime library (libgfortran). The warning related to how memory was being deallocated and a pointer was being nullified. The fix ensures that after the format data is freed, the pointer tracking that memory is properly set to null, preventing potential issues like use-after-free.

Filed Under: libfortranstatic analysismemory managementbugfix