[gcc/devel/omp/gcc-16] OpenMP: Add omp_get_device_distances routine: Gracefully handle failure to open Linux sysfs file for

Sandra Loosemore via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:566ad013548bd977f29f4b677a16867af71e33e4

commit 566ad013548bd977f29f4b677a16867af71e33e4
Author: Thomas Schwinge <[email protected]>
Date:   Tue Jun 30 08:55:08 2026 +0200

    OpenMP: Add omp_get_device_distances routine: Gracefully handle failure to open Linux sysfs file for NUMA node [PR125877]
    
    Fix-up for commit 8af1592882509fbead16e30fd2d056330a9609e4
    "OpenMP: Add omp_get_device_distances routine [PR125877]".  Without this,
    'libgomp/config/linux/numa.c:gomp_get_numa_distance' faults when trying to
    'fscanf' from the null pointer upon 'fopen' failure.
    
            PR libgomp/125877
            libgomp/
            * config/linux/numa.c (gomp_get_numa_distance): Gracefully handle
            failure to open Linux sysfs file for NUMA node.
    
    (cherry picked from commit c1c66ede4052c2697f3dd17b80f8b80ff3fc2368)

Diff:
---
 libgomp/config/linux/numa.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libgomp/config/linux/numa.c b/libgomp/config/linux/numa.c
index d43b34b98dd1..a3d84870e6e8 100644
--- a/libgomp/config/linux/numa.c
+++ b/libgomp/config/linux/numa.c
@@ -85,6 +85,11 @@ gomp_get_numa_distance (int node1, int node2)
 	    return -1;
 	  int distance = -1;
 	  FILE *in = fopen (filename, "r");
+	  if (!in)
+	    {
+	      free (numa_distances);
+	      return -1;
+	    }
 	  for (int j = 0; j < cnt; j++)
 	    {
 	      fscanf (in, "%d", &distance);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.