mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Use try-with-resource to prevent output stream to be leaked in BlobProvider
Summary: This diff fixes a potential memory leak which can occur if an exception is thrown inside the try block and `outputStream.close()` is not called. By wrapping `outputStream.write(data)` inside try-with-resource we guarantee that outputStream will be closed regardless of whether the try statement completes normally or abruptly. Reviewed By: sammy-SC Differential Revision: D16148850 fbshipit-source-id: c5c0a78b36375857f6e717bb581e8686a4a94bb9
This commit is contained in:
committed by
Facebook Github Bot
parent
ddd7775b38
commit
8e4b2e7448
@@ -85,10 +85,8 @@ public final class BlobProvider extends ContentProvider {
|
||||
ParcelFileDescriptor readSide = pipe[0];
|
||||
ParcelFileDescriptor writeSide = pipe[1];
|
||||
|
||||
OutputStream outputStream = new ParcelFileDescriptor.AutoCloseOutputStream(writeSide);
|
||||
try {
|
||||
try (OutputStream outputStream = new ParcelFileDescriptor.AutoCloseOutputStream(writeSide)) {
|
||||
outputStream.write(data);
|
||||
outputStream.close();
|
||||
} catch (IOException exception) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user