Bug 1474967: Fix resource leaks. r=nalexander
authorRobert Bartlensky <rbartlensky@mozilla.com>
Wed, 11 Jul 2018 18:30:25 +0100
changeset 427107 dd8b72cfda82
parent 427106 d28be9c59ecb
child 427108 b3e82720e36c
push id34292
push usercsabou@mozilla.com
push dateWed, 18 Jul 2018 17:18:53 +0000
treeherdermozilla-central@10ca5b14dbdb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1474967
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1474967: Fix resource leaks. r=nalexander MozReview-Commit-ID: GzENpXSdltH
mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/GeckoMediaDrmBridgeV21.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/GeckoMediaDrmBridgeV21.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/GeckoMediaDrmBridgeV21.java
@@ -468,34 +468,35 @@ public class GeckoMediaDrmBridgeV21 impl
         PostRequestTask(int promiseId, String url, byte[] drmRequest) {
             this.mPromiseId = promiseId;
             this.mURL = url;
             this.mDrmRequest = drmRequest;
         }
 
         @Override
         protected Void doInBackground(Void... params) {
+            HttpURLConnection urlConnection = null;
+            BufferedReader in = null;
             try {
                 URI finalURI = new URI(mURL + "&signedRequest=" + URLEncoder.encode(new String(mDrmRequest), "UTF-8"));
-                HttpURLConnection urlConnection = (HttpURLConnection) ProxySelector.openConnectionWithProxy(finalURI);
+                urlConnection = (HttpURLConnection) ProxySelector.openConnectionWithProxy(finalURI);
                 urlConnection.setRequestMethod("POST");
                 if (DEBUG) Log.d(LOGTAG, "Provisioning, posting url =" + finalURI.toString());
 
                 // Add data
                 urlConnection.setRequestProperty("Accept", "*/*");
                 urlConnection.setRequestProperty("User-Agent", getCDMUserAgent());
                 urlConnection.setRequestProperty("Content-Type", "application/json");
 
                 // Execute HTTP Post Request
                 urlConnection.connect();
 
                 int responseCode = urlConnection.getResponseCode();
                 if (responseCode == HttpURLConnection.HTTP_OK) {
-                    BufferedReader in =
-                      new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), StringUtils.UTF_8));
+                    in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), StringUtils.UTF_8));
                     String inputLine;
                     StringBuffer response = new StringBuffer();
 
                     while ((inputLine = in.readLine()) != null) {
                         response.append(inputLine);
                     }
                     in.close();
                     mResponseBody = String.valueOf(response).getBytes(StringUtils.UTF_8);
@@ -503,16 +504,27 @@ public class GeckoMediaDrmBridgeV21 impl
                     if (mResponseBody != null) Log.d(LOGTAG, "response length=" + mResponseBody.length);
                 } else {
                     Log.d(LOGTAG, "Provisioning, server returned HTTP error code :" + responseCode);
                 }
             } catch (IOException e) {
                 Log.e(LOGTAG, "Got exception during posting provisioning request ...", e);
             } catch (URISyntaxException e) {
                 Log.e(LOGTAG, "Got exception during creating uri ...", e);
+            } finally {
+                if (urlConnection != null) {
+                    urlConnection.disconnect();
+                }
+                try {
+                    if (in != null) {
+                        in.close();
+                    }
+                } catch (IOException e) {
+                    Log.e(LOGTAG, "Exception during closing in ...", e);
+                }
             }
             return null;
         }
 
         @Override
         protected void onPostExecute(Void v) {
             onProvisionResponse(mPromiseId, mResponseBody);
         }