Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions firebase-installations/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Unreleased

- [fixed] Closed the response stream when deleting an installation to avoid a StrictMode
`LeakedClosableViolation`.

# 19.1.2

- [changed] Migrated from SharedPreferences to DataStore (#8355)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ public void deleteFirebaseInstallation(
int httpResponseCode = httpURLConnection.getResponseCode();

if (httpResponseCode == 200 || httpResponseCode == 401 || httpResponseCode == 404) {
closeResponseStream(httpURLConnection, httpResponseCode);
return;
}

Expand Down Expand Up @@ -453,6 +454,23 @@ private static boolean isSuccessfulResponseCode(int responseCode) {
return responseCode >= 200 && responseCode < 300;
}

// Close the response stream so decoders backing it (for example, the gzip Inflater on Android's
// HttpURLConnection) are released eagerly. disconnect() alone does not reliably release them,
// which triggers StrictMode LeakedClosableViolation when the finalizer runs.
private static void closeResponseStream(HttpURLConnection conn, int httpResponseCode) {
try {
InputStream stream =
isSuccessfulResponseCode(httpResponseCode)
? conn.getInputStream()
: conn.getErrorStream();
if (stream != null) {
stream.close();
}
} catch (IOException ignored) {

}
}

private static void logBadConfigError() {
Log.e(
FIS_TAG,
Expand Down