Explorar o código

close streams after use

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger %!s(int64=2) %!d(string=hai) anos
pai
achega
8acb646383

+ 5 - 0
app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

@@ -1551,6 +1551,11 @@ class ChatController(args: Bundle) :
                 input.copyTo(output)
             }
         }
+        try {
+            fd.close()
+        } catch (e: IOException) {
+            Log.w(TAG, "Failed to close AssetFileDescriptor", e)
+        }
     }
 
     override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {

+ 3 - 1
app/src/main/java/com/nextcloud/talk/upload/normal/FileUploader.kt

@@ -55,8 +55,10 @@ class FileUploader(
         try {
             val input: InputStream = context.contentResolver.openInputStream(sourceFileUri)!!
             val buf = ByteArray(input.available())
-            while (input.read(buf) != -1)
+            while (input.read(buf) != -1) {
                 requestBody = RequestBody.create("application/octet-stream".toMediaTypeOrNull(), buf)
+            }
+            input.close()
         } catch (e: Exception) {
             Log.e(TAG, "failed to create RequestBody for $sourceFileUri", e)
         }