Commit 907a940f authored by Reza.Zakerinasab's avatar Reza.Zakerinasab Committed by Commit Bot

Fix memory leak in DecodingImageGenerator

Bug: 897190
Change-Id: I1c2d24bc3db26d5c27a582a6fd5049a16cabd927
Reviewed-on: https://chromium-review.googlesource.com/c/1291769Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Commit-Queue: Mohammad Reza Zakerinasab <zakerinasab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601636}
parent 2ea43a09
...@@ -130,6 +130,7 @@ bool DecodingImageGenerator::GetPixels(const SkImageInfo& dst_info, ...@@ -130,6 +130,7 @@ bool DecodingImageGenerator::GetPixels(const SkImageInfo& dst_info,
// the requested color type from N32. // the requested color type from N32.
SkImageInfo target_info = dst_info; SkImageInfo target_info = dst_info;
char* memory = static_cast<char*>(pixels); char* memory = static_cast<char*>(pixels);
std::unique_ptr<char*> memory_ref_ptr;
size_t adjusted_row_bytes = row_bytes; size_t adjusted_row_bytes = row_bytes;
if ((target_info.colorType() != kN32_SkColorType) && if ((target_info.colorType() != kN32_SkColorType) &&
(target_info.colorType() != kRGBA_F16_SkColorType)) { (target_info.colorType() != kRGBA_F16_SkColorType)) {
...@@ -141,6 +142,7 @@ bool DecodingImageGenerator::GetPixels(const SkImageInfo& dst_info, ...@@ -141,6 +142,7 @@ bool DecodingImageGenerator::GetPixels(const SkImageInfo& dst_info,
adjusted_row_bytes = adjusted_row_bytes =
target_info.bytesPerPixel() * (row_bytes / dst_info.bytesPerPixel()); target_info.bytesPerPixel() * (row_bytes / dst_info.bytesPerPixel());
memory = new char[target_info.computeMinByteSize()]; memory = new char[target_info.computeMinByteSize()];
memory_ref_ptr = std::make_unique<char*>(memory);
} }
// Skip the check for alphaType. blink::ImageFrame may have changed the // Skip the check for alphaType. blink::ImageFrame may have changed the
...@@ -179,14 +181,14 @@ bool DecodingImageGenerator::GetPixels(const SkImageInfo& dst_info, ...@@ -179,14 +181,14 @@ bool DecodingImageGenerator::GetPixels(const SkImageInfo& dst_info,
} }
// Convert the color type to the requested one if necessary // Convert the color type to the requested one if necessary
if (decoded && target_info.colorType() != dst_info.colorType()) { if (target_info.colorType() != dst_info.colorType()) {
decoded = if (decoded) {
decoded && SkPixmap{target_info, memory, adjusted_row_bytes}.readPixels( decoded = decoded &&
SkPixmap{dst_info, pixels, row_bytes}); SkPixmap{target_info, memory, adjusted_row_bytes}.readPixels(
delete[] memory; SkPixmap{dst_info, pixels, row_bytes});
DCHECK(decoded); DCHECK(decoded);
}
} }
return decoded; return decoded;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment