Skip to content

Commit

Permalink
Fix the'ParcelFileDescriptor not closed' bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wushuai1415 authored and huiguangjun committed Jul 23, 2021
1 parent cf8745b commit 591cfa2
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.alibaba.sdk.android.oss.network;

import android.os.ParcelFileDescriptor;

import com.alibaba.sdk.android.oss.ClientException;
import com.alibaba.sdk.android.oss.ServiceException;
import com.alibaba.sdk.android.oss.common.OSSHeaders;
Expand Down Expand Up @@ -129,7 +131,15 @@ public T call() throws Exception {
}
} else if (message.getUploadUri() != null) {
inputStream = context.getApplicationContext().getContentResolver().openInputStream(message.getUploadUri());
length = context.getApplicationContext().getContentResolver().openFileDescriptor(message.getUploadUri(), "r").getStatSize();
ParcelFileDescriptor parcelFileDescriptor = null;
try {
parcelFileDescriptor = context.getApplicationContext().getContentResolver().openFileDescriptor(message.getUploadUri(), "r");
length = parcelFileDescriptor.getStatSize();
} finally {
if (parcelFileDescriptor != null) {
parcelFileDescriptor.close();
}
}
} else if (message.getContent() != null) {
inputStream = message.getContent();
length = message.getContentLength();
Expand Down

0 comments on commit 591cfa2

Please sign in to comment.