From b0d67064b5074d37e366e4cc0b3a335abe0ca749 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sun, 21 Jun 2020 18:46:53 +0300 Subject: [PATCH] Check for null FILE handles in ReportTopology On Linux `/sys` is not guaranteed to exist. When it doesn't, tracy would crash with a SIGSEGV due to a nullptr dereference. Not actually sure how well tracy clients will handle the case where this information is missing, though. --- client/TracyProfiler.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index af858311..bb551870 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -2692,12 +2692,15 @@ void Profiler::ReportTopology() sprintf( path, "%s%i/topology/physical_package_id", basePath, i ); char buf[1024]; FILE* f = fopen( path, "rb" ); + if( f == nullptr ) { + tracy_free(cpuData); + return; + } auto read = fread( buf, 1, 1024, f ); buf[read] = '\0'; fclose( f ); cpuData[i].package = uint32_t( atoi( buf ) ); cpuData[i].thread = i; - sprintf( path, "%s%i/topology/core_id", basePath, i ); f = fopen( path, "rb" ); read = fread( buf, 1, 1024, f );