diff options
| author | 2023-06-06 06:12:31 +0000 | |
|---|---|---|
| committer | 2023-06-06 06:12:31 +0000 | |
| commit | 085a15ec35b0cf1305efd36f41b66cf2fb0c8adb (patch) | |
| tree | bad9b38c25096c04b212a10480555825f5fec423 /libs/ultrahdr/jpegencoderhelper.cpp | |
| parent | cc2916f94023bca254fdd06588e6770c25f22f00 (diff) | |
| parent | e12f984157a7ded6fe702b266203ed67648ceee7 (diff) | |
ultrahdr: release memory if encode/decode fails am: e69d9d2e7f am: e12f984157
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/23541809
Change-Id: Iafb07a5a4a8965921728377e91a9f7d9455b632c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'libs/ultrahdr/jpegencoderhelper.cpp')
| -rw-r--r-- | libs/ultrahdr/jpegencoderhelper.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/libs/ultrahdr/jpegencoderhelper.cpp b/libs/ultrahdr/jpegencoderhelper.cpp index ab2f8c7b5a..a03547b538 100644 --- a/libs/ultrahdr/jpegencoderhelper.cpp +++ b/libs/ultrahdr/jpegencoderhelper.cpp @@ -107,12 +107,11 @@ bool JpegEncoderHelper::encode(const void* image, int width, int height, int jpe jpeg_write_marker(&cinfo, JPEG_APP0 + 2, static_cast<const JOCTET*>(iccBuffer), iccSize); } - if (!compress(&cinfo, static_cast<const uint8_t*>(image), isSingleChannel)) { - return false; - } + bool status = compress(&cinfo, static_cast<const uint8_t*>(image), isSingleChannel); jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); - return true; + + return status; } void JpegEncoderHelper::setJpegDestination(jpeg_compress_struct* cinfo) { @@ -174,7 +173,7 @@ bool JpegEncoderHelper::compressYuv(jpeg_compress_struct* cinfo, const uint8_t* uint8_t* y_plane = const_cast<uint8_t*>(yuv); uint8_t* u_plane = const_cast<uint8_t*>(yuv + y_plane_size); uint8_t* v_plane = const_cast<uint8_t*>(yuv + y_plane_size + uv_plane_size); - std::unique_ptr<uint8_t[]> empty(new uint8_t[cinfo->image_width]); + std::unique_ptr<uint8_t[]> empty = std::make_unique<uint8_t[]>(cinfo->image_width); memset(empty.get(), 0, cinfo->image_width); const int aligned_width = ALIGNM(cinfo->image_width, kCompressBatchSize); @@ -250,7 +249,7 @@ bool JpegEncoderHelper::compressSingleChannel(jpeg_compress_struct* cinfo, const JSAMPARRAY planes[1] {y}; uint8_t* y_plane = const_cast<uint8_t*>(image); - std::unique_ptr<uint8_t[]> empty(new uint8_t[cinfo->image_width]); + std::unique_ptr<uint8_t[]> empty = std::make_unique<uint8_t[]>(cinfo->image_width); memset(empty.get(), 0, cinfo->image_width); const int aligned_width = ALIGNM(cinfo->image_width, kCompressBatchSize); |