From 035160fb849ed565fc419cd7deadb486338b755c Mon Sep 17 00:00:00 2001 From: Jay Wang Date: Mon, 22 Aug 2016 20:17:37 -0700 Subject: SnapdragonCamera: Fix memory leak when updating thumbnails. Fix a memory leak with jpeg data buffers saved for updating thumbnails. Ensure that all references are freed and released when exiting. CRs-Fixed: 1054441 Change-Id: Idc79f51f0e70b0b3e39d614ff3dd7f5d1f85aaad --- src/com/android/camera/CaptureModule.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/com/android/camera/CaptureModule.java') diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java index 92b95e5ec..85722457d 100644 --- a/src/com/android/camera/CaptureModule.java +++ b/src/com/android/camera/CaptureModule.java @@ -357,7 +357,6 @@ public class CaptureModule implements CameraModule, PhotoController, if (uri != null) { mActivity.notifyNewMedia(uri); } - if (mLastJpegData != null) mActivity.updateThumbnail(mLastJpegData); } } }; @@ -1353,7 +1352,6 @@ public class CaptureModule implements CameraModule, PhotoController, long date = (name == null) ? -1 : name.date; byte[] bytes = getJpegData(image); - mLastJpegData = bytes; ExifInterface exif = Exif.getExif(bytes); int orientation = Exif.getOrientation(exif); @@ -1361,6 +1359,12 @@ public class CaptureModule implements CameraModule, PhotoController, mActivity.getMediaSaveService().addImage(bytes, title, date, null, image.getWidth(), image.getHeight(), orientation, null, mOnMediaSavedListener, mContentResolver, "jpeg"); + + if(mLongshotActive) { + mLastJpegData = bytes; + } else { + mActivity.updateThumbnail(bytes); + } image.close(); } } @@ -1395,7 +1399,6 @@ public class CaptureModule implements CameraModule, PhotoController, ByteBuffer buffer = image.getPlanes()[0].getBuffer(); byte[] bytes = new byte[buffer.remaining()]; - mLastJpegData = bytes; buffer.get(bytes); ExifInterface exif = Exif.getExif(bytes); @@ -1404,6 +1407,8 @@ public class CaptureModule implements CameraModule, PhotoController, mActivity.getMediaSaveService().addImage(bytes, title, date, null, image.getWidth(), image.getHeight(), orientation, null, mOnMediaSavedListener, mContentResolver, "jpeg"); + + mActivity.updateThumbnail(bytes); image.close(); } }, mImageAvailableHandler); @@ -1716,6 +1721,7 @@ public class CaptureModule implements CameraModule, PhotoController, mUI.hideSurfaceView(); mFirstPreviewLoaded = false; stopBackgroundThread(); + mLastJpegData = null; } @Override @@ -3490,7 +3496,6 @@ public class CaptureModule implements CameraModule, PhotoController, byte[] bayerBytes = getJpegData(bayerImage); byte[] monoBytes = getJpegData(monoImage); - mLastJpegData = bayerBytes; ExifInterface exif = Exif.getExif(bayerBytes); int orientation = Exif.getOrientation(exif); @@ -3498,6 +3503,8 @@ public class CaptureModule implements CameraModule, PhotoController, null, bayerBytes, monoBytes, width, height, title, date, null, orientation, mOnMediaSavedListener, mContentResolver, "jpeg"); + mActivity.updateThumbnail(bayerBytes); + bayerImage.close(); bayerImage = null; monoImage.close(); -- cgit v1.2.3