Skip to content

Commit f5cf680

Browse files
Ivan Timokhinfacebook-github-bot
Ivan Timokhin
authored andcommitted
Fix filestream checking in output_json.cpp (#1063)
Summary: The code is missing several checks for file stream validity, which causes the traced application to crash when it is unable to create a file. Pull Request resolved: #1063 Reviewed By: aaronenyeshi Differential Revision: D71902855 Pulled By: sraikund16 fbshipit-source-id: 1b139b4e154cc3cc017a46a705433bc0bd6eebdb
1 parent 7cb6ac6 commit f5cf680

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

libkineto/src/output_json.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ void ChromeTraceLogger::metadataToJSON(
118118
void ChromeTraceLogger::handleTraceStart(
119119
const std::unordered_map<std::string, std::string>& metadata,
120120
const std::string& device_properties) {
121+
if (!traceOf_) {
122+
return;
123+
}
124+
121125
traceOf_ << fmt::format(
122126
R"JSON(
123127
{{
@@ -556,10 +560,16 @@ void ChromeTraceLogger::handleActivity(const libkineto::ITraceActivity& op) {
556560

557561
void ChromeTraceLogger::handleGenericActivity(
558562
const libkineto::GenericTraceActivity& op) {
563+
if (!traceOf_) {
564+
return;
565+
}
559566
handleActivity(op);
560567
}
561568

562569
void ChromeTraceLogger::handleGenericLink(const ITraceActivity& act) {
570+
if (!traceOf_) {
571+
return;
572+
}
563573
static struct {
564574
int type;
565575
char name[16];

0 commit comments

Comments
 (0)