Skip to content

Commit

Permalink
Fix strict mode warning on ParcelFileDescriptor leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Kifer committed Aug 17, 2016
1 parent ed95703 commit c27e305
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public static void flush(OutputStream stream) throws ChooserException {
}
}

public static void close(ParcelFileDescriptor parcelFileDescriptor) throws ChooserException {
if (parcelFileDescriptor != null) {
try {
parcelFileDescriptor.close();
} catch (IOException e) {
throw new ChooserException(e);
}
}
}

public static void verifyCursor(Uri uri, Cursor cursor) throws ChooserException {
if(cursor == null) {
throw new ChooserException("Didnt not get cursor in return for = " + uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,12 +552,13 @@ protected void processGooglePhotosMedia(String path, String extension)

BufferedInputStream inputStream = null;
BufferedOutputStream outStream = null;
ParcelFileDescriptor parcelFileDescriptor = null;

try {

filePath = FileUtils.getDirectory(foldername) + File.separator
+ Calendar.getInstance().getTimeInMillis() + extension;
ParcelFileDescriptor parcelFileDescriptor = context
parcelFileDescriptor = context
.getContentResolver().openFileDescriptor(Uri.parse(path),
"r");

Expand Down Expand Up @@ -585,6 +586,7 @@ protected void processGooglePhotosMedia(String path, String extension)
flush(outStream);
close(outStream);
close(inputStream);
close(parcelFileDescriptor);
}


Expand All @@ -609,12 +611,13 @@ protected ChosenVideo processGooglePhotosMediaNewVideo(String path, String exten

BufferedInputStream inputStream = null;
BufferedOutputStream outStream = null;
ParcelFileDescriptor parcelFileDescriptor = null;
String localPath;
try {

localPath = FileUtils.getDirectory(foldername) + File.separator
+ Calendar.getInstance().getTimeInMillis() + extension;
ParcelFileDescriptor parcelFileDescriptor = context
parcelFileDescriptor = context
.getContentResolver().openFileDescriptor(Uri.parse(path),
"r");

Expand Down Expand Up @@ -642,6 +645,7 @@ protected ChosenVideo processGooglePhotosMediaNewVideo(String path, String exten
flush(outStream);
close(outStream);
close(inputStream);
close(parcelFileDescriptor);
}


Expand All @@ -668,12 +672,13 @@ protected ChosenImage processGooglePhotosMediaNew(String path, String extension)

BufferedInputStream inputStream = null;
BufferedOutputStream outStream = null;
ParcelFileDescriptor parcelFileDescriptor = null;

try {

outFile = FileUtils.getDirectory(foldername) + File.separator
+ Calendar.getInstance().getTimeInMillis() + extension;
ParcelFileDescriptor parcelFileDescriptor = context
parcelFileDescriptor = context
.getContentResolver().openFileDescriptor(Uri.parse(path),
"r");

Expand Down Expand Up @@ -701,6 +706,7 @@ protected ChosenImage processGooglePhotosMediaNew(String path, String extension)
flush(outStream);
close(outStream);
close(inputStream);
close(parcelFileDescriptor);
}


Expand Down

0 comments on commit c27e305

Please sign in to comment.