diff --git a/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java b/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java index 9ba2bc42..cee6c8db 100644 --- a/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java +++ b/src/org/kde/kdeconnect/Backends/LanBackend/LanLink.java @@ -125,6 +125,7 @@ public class LanLink extends BaseLink { callback.sendProgress((int)(progress / np.getPayloadSize())); } } + stream.close(); Log.i("KDE/LanLink", "Finished sending payload"); } catch (Exception e) { Log.e("KDE/sendPackage", "Exception: "+e); @@ -176,13 +177,15 @@ public class LanLink extends BaseLink { if (np.hasPayloadTransferInfo()) { + Socket socket = null; try { - Socket socket = new Socket(); + socket = new Socket(); int tcpPort = np.getPayloadTransferInfo().getInt("port"); InetSocketAddress address = (InetSocketAddress)session.getRemoteAddress(); socket.connect(new InetSocketAddress(address.getAddress(), tcpPort)); np.setPayload(socket.getInputStream(), np.getPayloadSize()); } catch (Exception e) { + try { socket.close(); } catch(Exception ignored) { } e.printStackTrace(); Log.e("KDE/LanLink", "Exception connecting to payload remote socket"); } diff --git a/src/org/kde/kdeconnect/Helpers/StorageHelper.java b/src/org/kde/kdeconnect/Helpers/StorageHelper.java index 1d08b05c..a2a992c1 100644 --- a/src/org/kde/kdeconnect/Helpers/StorageHelper.java +++ b/src/org/kde/kdeconnect/Helpers/StorageHelper.java @@ -81,7 +81,9 @@ public class StorageHelper { if (storage.exists() && storage.isDirectory()) { String mounts = null; try { - mounts = new Scanner( new File("/proc/mounts") ).useDelimiter("\\A").next(); + Scanner scanner = new Scanner( new File("/proc/mounts") ); + mounts = scanner.useDelimiter("\\A").next(); + scanner.close(); //Log.e("Mounts",mounts); } catch(Exception e) { e.printStackTrace(); diff --git a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java index d6fd43f6..903a3205 100644 --- a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java +++ b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java @@ -64,13 +64,14 @@ public class NotificationFilterActivity extends ActionBarActivity { res.moveToNext(); i++; } + res.close(); appDatabase.close(); ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice,android.R.id.text1, appName); listView.setAdapter(adapter); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); - for (i = 0 ; i < res.getCount(); i++){ + for (i = 0 ; i < isFiltered.length; i++){ if (isFiltered[i]) { listView.setItemChecked(i, true); } @@ -85,6 +86,7 @@ public class NotificationFilterActivity extends ActionBarActivity { appDatabase.close(); } }); + } // Delete apps from database which are uninstalled @@ -101,6 +103,7 @@ public class NotificationFilterActivity extends ActionBarActivity { } res.moveToNext(); } + res.close(); } appDatabase.close(); diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java index b1b920aa..76ef21e3 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java @@ -235,12 +235,13 @@ public class ShareActivity extends ActionBarActivity { try { size = new File(uri.getPath()).length(); - np.setPayload(inputStream, size); } catch(Exception e) { Log.e("ShareActivity", "Could not obtain file size"); e.printStackTrace(); } + np.setPayload(inputStream, size); + }else{ // Probably a content:// uri, so we query the Media content provider diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java index 3c6af431..8de43ec4 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java @@ -141,8 +141,9 @@ public class SharePlugin extends Plugin { new Thread(new Runnable() { @Override public void run() { + OutputStream output = null; try { - OutputStream output = new FileOutputStream(destinationFullPath.getPath()); + output = new FileOutputStream(destinationFullPath.getPath()); byte data[] = new byte[1024]; long progress = 0, prevProgressPercentage = 0; int count; @@ -162,9 +163,16 @@ public class SharePlugin extends Plugin { } output.flush(); - output.close(); - input.close(); + } catch (Exception e) { + Log.e("SharePlugin", "Receiver thread exception"); + e.printStackTrace(); + } finally { + try { output.close(); } catch (Exception e) {} + try { input.close(); } catch (Exception e) {} + } + + try { Log.i("SharePlugin", "Transfer finished"); //Make sure it is added to the Android Gallery