Skip to content

Commit 8d29567

Browse files
author
Alexander Batashev
authored
[SYCL] Fix potential nullptr dereference (#5761)
Static analysis tool complained about this code.
1 parent 879c3ae commit 8d29567

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sycl/tools/sycl-prof/collector.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "xpti/xpti_data_types.h"
1111

1212
#include <cstdint>
13+
#include <cstdlib>
1314
#include <xpti/xpti_trace_framework.h>
1415

1516
#include <chrono>
@@ -62,7 +63,11 @@ XPTI_CALLBACK_API void xptiTraceInit(unsigned int /*major_version*/,
6263
const char * /*version_str*/,
6364
const char *StreamName) {
6465
if (GWriter == nullptr) {
65-
GWriter = new JSONWriter(std::getenv("SYCL_PROF_OUT_FILE"));
66+
const char *ProfOutFile = std::getenv("SYCL_PROF_OUT_FILE");
67+
if (!ProfOutFile)
68+
throw std::runtime_error(
69+
"SYCL_PROF_OUT_FILE environment variable is not specified");
70+
GWriter = new JSONWriter(ProfOutFile);
6671
GWriter->init();
6772
}
6873

0 commit comments

Comments
 (0)