Skip to content

Commit 04a2b57

Browse files
authored
crashlytics: Fix flaky tests caused by EXC_GUARD on stdin (#15583)
1 parent 3c872e2 commit 04a2b57

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Crashlytics/Crashlytics/Helpers/FIRCLSFile.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,13 @@ bool FIRCLSFileCloseWithOffset(FIRCLSFile* file, off_t* finalSize) {
175175
*finalSize = file->writtenLength;
176176
}
177177

178-
if (close(file->fd) != 0) {
179-
FIRCLSSDKLog("Error: Unable to close file %s\n", strerror(errno));
180-
return false;
178+
// If the FIRCLSFile struct was zero-initialized (e.g. via memset) and never opened,
179+
// fd will be 0. Closing fd 0 triggers a system-level EXC_GUARD crash.
180+
if (file->fd > STDERR_FILENO) {
181+
if (close(file->fd) != 0) {
182+
FIRCLSSDKLog("Error: Unable to close file %s\n", strerror(errno));
183+
return false;
184+
}
181185
}
182186

183187
memset(file, 0, sizeof(FIRCLSFile));

0 commit comments

Comments
 (0)