Close the ApplicationExitInfo trace stream in Crashlytics NDK - #8531
Close the ApplicationExitInfo trace stream in Crashlytics NDK#8531jrodiz wants to merge 3 commits into
Conversation
The stream from getTraceInputStream() wraps a ParcelFileDescriptor that is only released on close, so leaving it open leaked an fd until finalization and tripped StrictMode CloseGuard. Fixes firebase#8510.
Covers that the ApplicationExitInfo trace stream is closed on success and on read failure, plus the null-trace path and the round trip of convertInputStreamToString.
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
Fixes #8510
Problem
CrashpadController.getTraceFileFromApplicationExitInfo()drained the stream returned byApplicationExitInfo.getTraceInputStream()but never closed it. That stream wraps aParcelFileDescriptor.AutoCloseInputStream, soclose()is the only thing that releases the file descriptor — without it the fd survives until finalization and tripsCloseGuardunderStrictMode.detectLeakedClosableObjects():Crashlytics runs this during background init to finalize the previous session, so it leaks on every app start following a native crash.
Fix
Close at the acquisition site with try-with-resources, releasing the fd on normal completion, read failure and encode failure alike:
convertInputStreamToStringis left untouched — ownership stays with the caller. Visibility was relaxed to@VisibleForTesting staticfor coverage.getTraceInputStream()may returnnull, and try-with-resources null-checks beforeclose()(JLS 14.20.3.1), so that path is unchanged.Scope
SessionReportingCoordinator's ANR path calls the same API but already closes the stream via aBufferedInputStreamin try-with-resources. Those are the only two call sites, so this change stays confined to the NDK module.Risk
Low. The stream was already read to EOF before being abandoned, so closing it adds no new failure mode; a throwing
close()lands in the existingcatch (IOException)and degrades to today's "trace unavailable" →nullbehaviour. The visibility change is source- and binary-safe: the method is not part of any public or@KeepForSdkAPI surface, andapi.txtis unaffected.