From 3641579cc8c7c9ccac500e41a99f5b5215ffd21a Mon Sep 17 00:00:00 2001 From: "dswitkin@google.com" Date: Mon, 16 Aug 2010 15:34:00 +0000 Subject: [PATCH 1/1] Fixed the double delete problem remaining in issue 503. git-svn-id: http://zxing.googlecode.com/svn/trunk@1536 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../src/zxing/common/GreyscaleLuminanceSource.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cpp/core/src/zxing/common/GreyscaleLuminanceSource.cpp b/cpp/core/src/zxing/common/GreyscaleLuminanceSource.cpp index 07c8ba26..4910b653 100644 --- a/cpp/core/src/zxing/common/GreyscaleLuminanceSource.cpp +++ b/cpp/core/src/zxing/common/GreyscaleLuminanceSource.cpp @@ -48,14 +48,16 @@ unsigned char* GreyscaleLuminanceSource::getRow(int y, unsigned char* row) { } unsigned char* GreyscaleLuminanceSource::getMatrix() { - if (left_ != 0 || top_ != 0 || dataWidth_ != width_ || dataHeight_ != height_) { - unsigned char* cropped = new unsigned char[width_ * height_]; + int size = width_ * height_; + unsigned char* result = new unsigned char[size]; + if (left_ == 0 && top_ == 0 && dataWidth_ == width_ && dataHeight_ == height_) { + memcpy(result, greyData_, size); + } else { for (int row = 0; row < height_; row++) { - memcpy(cropped + row * width_, greyData_ + (top_ + row) * dataWidth_ + left_, width_); + memcpy(result + row * width_, greyData_ + (top_ + row) * dataWidth_ + left_, width_); } - return cropped; } - return greyData_; + return result; } Ref GreyscaleLuminanceSource::rotateCounterClockwise() { -- 2.20.1