diff options
author | cyBerta <cyberta@riseup.net> | 2021-07-15 00:04:36 +0200 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2021-07-21 22:02:28 +0200 |
commit | aa43298684367000cadf16037cb90c366ac3c000 (patch) | |
tree | 0a1564a0a0fad027d76e8d9185c70d69bd927d26 | |
parent | 3c15fc1fb3cfb1537e2dfad740921c5f1d063259 (diff) |
ensure that response.body().close() is always called when reading non-null API responses
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiConnector.java | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiConnector.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiConnector.java index c863abd4..35ad9cd2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiConnector.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiConnector.java @@ -95,10 +95,15 @@ public class ProviderApiConnector { if (!response.isSuccessful()) { VpnStatus.logWarning("[API] API request failed: " + url); } - InputStream inputStream = response.body().byteStream(); - Scanner scanner = new Scanner(inputStream).useDelimiter("\\A"); - if (scanner.hasNext()) { - return scanner.next(); + + if (response.body() != null) { + InputStream inputStream = response.body().byteStream(); + Scanner scanner = new Scanner(inputStream).useDelimiter("\\A"); + if (scanner.hasNext()) { + String result = scanner.next(); + response.body().close(); + return result; + } } return null; } |