Эх сурвалжийг харах

Release connections after usage

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 5 жил өмнө
parent
commit
4b30ed5993

+ 7 - 1
src/main/java/com/nextcloud/client/network/ConnectivityServiceImpl.java

@@ -71,6 +71,8 @@ class ConnectivityServiceImpl implements ConnectivityService {
     @Override
     public boolean isInternetWalled() {
         if (isOnlineWithWifi()) {
+
+            GetMethod get = null;
             try {
                 Server server = accountManager.getUser().getServer();
                 String baseServerAddress = server.getUri().toString();
@@ -84,7 +86,7 @@ class ConnectivityServiceImpl implements ConnectivityService {
                     url = baseServerAddress + "/status.php";
                 }
 
-                GetMethod get = requestBuilder.invoke(url);
+                get = requestBuilder.invoke(url);
                 HttpClient client = clientFactory.createPlainClient();
 
                 int status = client.executeMethod(get);
@@ -108,6 +110,10 @@ class ConnectivityServiceImpl implements ConnectivityService {
                 }
             } catch (IOException e) {
                 logger.e(TAG, "Error checking internet connection", e);
+            } finally {
+                if (get != null) {
+                    get.releaseConnection();
+                }
             }
         } else {
             return getActiveNetworkType() == JobRequest.NetworkType.ANY;

+ 2 - 0
src/main/java/com/owncloud/android/jobs/NotificationJob.java

@@ -365,6 +365,8 @@ public class NotificationJob extends Job {
                 return client.executeMethod(method);
             } catch (IOException e) {
                 Log_OC.e(TAG, "Execution of notification action failed: " + e);
+            } finally {
+                method.releaseConnection();
             }
             return 0;
         }

+ 2 - 0
src/main/java/com/owncloud/android/ui/asynctasks/NotificationExecuteActionTask.java

@@ -71,6 +71,8 @@ public class NotificationExecuteActionTask extends AsyncTask<Action, Void, Boole
         } catch (IOException e) {
             Log_OC.e(this, "Execution of notification action failed: " + e);
             return Boolean.FALSE;
+        } finally {
+            method.releaseConnection();
         }
 
         return status == HttpStatus.SC_OK || status == HttpStatus.SC_ACCEPTED;

+ 6 - 1
src/main/java/com/owncloud/android/ui/asynctasks/PrintAsyncTask.java

@@ -75,10 +75,11 @@ public class PrintAsyncTask extends AsyncTask<Void, Void, Boolean> {
     @Override
     protected Boolean doInBackground(Void... voids) {
         HttpClient client = new HttpClient();
-        GetMethod getMethod = new GetMethod(url);
+        GetMethod getMethod = null;
 
         FileOutputStream fos;
         try {
+            getMethod = new GetMethod(url);
             int status = client.executeMethod(getMethod);
             if (status == HttpStatus.SC_OK) {
                 if (file.exists() && !file.delete()) {
@@ -122,6 +123,10 @@ public class PrintAsyncTask extends AsyncTask<Void, Void, Boolean> {
             }
         } catch (IOException e) {
             Log_OC.e(TAG, "Error reading file", e);
+        } finally {
+            if (getMethod != null) {
+                getMethod.releaseConnection();
+            }
         }
 
         return Boolean.TRUE;

+ 5 - 1
src/main/java/com/owncloud/android/utils/glide/HttpStreamFetcher.java

@@ -58,7 +58,7 @@ public class HttpStreamFetcher implements DataFetcher<InputStream> {
         OwnCloudClient client = clientFactory.create(user);
 
         if (client != null) {
-            GetMethod get;
+            GetMethod get = null;
             try {
                 get = new GetMethod(url);
                 get.setRequestHeader("Cookie", "nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");
@@ -71,6 +71,10 @@ public class HttpStreamFetcher implements DataFetcher<InputStream> {
                 }
             } catch (Exception e) {
                 Log_OC.e(TAG, e.getMessage(), e);
+            } finally {
+                if (get != null) {
+                    get.releaseConnection();
+                }
             }
         }
         return null;