From 1a72683b52a8bc3080fc7514bf7fdc4f15951211 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 29 Apr 2017 22:59:36 +0200 Subject: [PATCH] close http download connection after download --- .../siacs/conversations/http/HttpDownloadConnection.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java index cd49b7981..68d5fc787 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java @@ -219,6 +219,7 @@ public class HttpDownloadConnection implements Transferable { } return Long.parseLong(contentLength, 10); } catch (IOException e) { + Log.d(Config.LOGTAG,"io exception during HEAD "+e.getMessage()); throw e; } catch (NumberFormatException e) { throw new IOException(); @@ -259,10 +260,10 @@ public class HttpDownloadConnection implements Transferable { private void download() throws Exception { InputStream is = null; + HttpURLConnection connection = null; PowerManager.WakeLock wakeLock = mHttpConnectionManager.createWakeLock("http_download_"+message.getUuid()); try { wakeLock.acquire(); - HttpURLConnection connection; if (mUseTor) { connection = (HttpURLConnection) mUrl.openConnection(mHttpConnectionManager.getProxy()); } else { @@ -322,10 +323,14 @@ public class HttpDownloadConnection implements Transferable { throw new FileWriterException(); } } catch (CancellationException | IOException e) { + Log.d(Config.LOGTAG,"http download failed "+e.getMessage()); throw e; } finally { FileBackend.close(os); FileBackend.close(is); + if (connection != null) { + connection.disconnect(); + } wakeLock.release(); } }