Skip to content

Commit 9466be9

Browse files
authored
fix resource leak (#634)
:
1 parent a734af6 commit 9466be9

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

firebase-config/src/main/java/com/google/firebase/remoteconfig/internal/ConfigStorageClient.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,10 @@ public synchronized Void write(ConfigContainer container) throws IOException {
9393
*/
9494
@Nullable
9595
public synchronized ConfigContainer read() throws IOException {
96+
97+
FileInputStream fileInputStream = null;
9698
try {
97-
context.openFileInput(fileName);
98-
} catch (FileNotFoundException e) {
99-
return null;
100-
}
101-
FileInputStream fileInputStream = context.openFileInput(fileName);
102-
try {
99+
fileInputStream = context.openFileInput(fileName);
103100
byte[] bytes = new byte[fileInputStream.available()];
104101
fileInputStream.read(bytes, 0, bytes.length);
105102
String containerJsonString = new String(bytes, JSON_STRING_ENCODING);
@@ -110,7 +107,7 @@ public synchronized ConfigContainer read() throws IOException {
110107
// File might not have been written to yet, so this not an irrecoverable error.
111108
return null;
112109
} finally {
113-
fileInputStream.close();
110+
if (fileInputStream != null) fileInputStream.close();
114111
}
115112
}
116113

0 commit comments

Comments
 (0)