GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
libgomp

libgomp: Improve robustness of omp_get_numa_distance with getline

Fixes potential crashes and double-free issues in libgomp's NUMA distance calculation by robustifying getline usage.

This commit enhances the robustness of libgomp’s omp_get_numa_distance function, specifically addressing issues related to parsing NUMA information from /sys/devices/system/node/online. It resolves a potential crash caused by freeing an uninitialized pointer (lineptr) when getline fails early and prevents a double-free in error handling paths. The code now correctly initializes lineptr and nline before calling getline and simplifies the error handling logic.

In Details

The gomp_get_numa_distance function in libgomp's NUMA configuration code (linux/numa.c) exhibited undefined behavior when getline failed before lineptr was initialized. This commit moves the initialization of lineptr and nline to occur before the getline call, ensuring free(lineptr) in the error path is safe. It also consolidates the error handling to avoid a double-free scenario.

For Context
NUMA
Non-Uniform Memory Access. A memory architecture where memory access times depend on the memory location relative to the processor. Systems often have multiple NUMA nodes, and optimizing memory access patterns is crucial for performance.
getline
A C standard library function that reads a line from a specified stream, which can include dynamically allocating a buffer to hold the line. It's commonly used for parsing configuration files or stream input.
double-free
A programming error in C/C++ where the free() function is called twice on the same memory address. This can lead to heap corruption and program crashes.
Filed Under: libgompNUMAmemoryrobustnessbugfix