From 30c599079a16b8d615bb796d78e664ea1807b604 Mon Sep 17 00:00:00 2001 From: Dmitry Gerasimov Date: Fri, 14 Feb 2020 14:27:45 +0300 Subject: [PATCH] Free allocated memory before throwing exceptions --- .../datamatrix/decoder/DataMatrixDecodedBitStreamParser.cpp | 1 + src/zxing/zxing/qrcode/decoder/QRDecodedBitStreamParser.cpp | 1 + src/zxing/zxing/qrcode/encoder/QREncoder.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/src/zxing/zxing/datamatrix/decoder/DataMatrixDecodedBitStreamParser.cpp b/src/zxing/zxing/datamatrix/decoder/DataMatrixDecodedBitStreamParser.cpp index 839a079..652b323 100644 --- a/src/zxing/zxing/datamatrix/decoder/DataMatrixDecodedBitStreamParser.cpp +++ b/src/zxing/zxing/datamatrix/decoder/DataMatrixDecodedBitStreamParser.cpp @@ -404,6 +404,7 @@ void DecodedBitStreamParser::decodeBase256Segment(Ref bits, ostringst // Have seen this particular error in the wild, such as at // http://www.bcgen.com/demo/IDAutomationStreamingDataMatrix.aspx?MODE=3&D=Fred&PFMT=3&PT=F&X=0.3&O=0&LM=0.2 if (bits->available() < 8) { + delete [] bytes; throw FormatException("byteSegments"); } bytes[i] = unrandomize255State(bits->readBits(8), codewordPosition++); diff --git a/src/zxing/zxing/qrcode/decoder/QRDecodedBitStreamParser.cpp b/src/zxing/zxing/qrcode/decoder/QRDecodedBitStreamParser.cpp index 14ea4d7..78d8391 100644 --- a/src/zxing/zxing/qrcode/decoder/QRDecodedBitStreamParser.cpp +++ b/src/zxing/zxing/qrcode/decoder/QRDecodedBitStreamParser.cpp @@ -229,6 +229,7 @@ void DecodedBitStreamParser::decodeNumericSegment(Ref bits, std::stri while (count >= 3) { // Each 10 bits encodes three digits if (bits->available() < 10) { + delete[] bytes; throw ReaderException("format exception"); } int threeDigitsBits = bits->readBits(10); diff --git a/src/zxing/zxing/qrcode/encoder/QREncoder.cpp b/src/zxing/zxing/qrcode/encoder/QREncoder.cpp index 4747058..9aead3f 100644 --- a/src/zxing/zxing/qrcode/encoder/QREncoder.cpp +++ b/src/zxing/zxing/qrcode/encoder/QREncoder.cpp @@ -416,6 +416,7 @@ BitArray* Encoder::interleaveWithECBytes(const BitArray& bits, message += " and "; message += zxing::common::StringUtils::intToStr(result->getSizeInBytes()); message += " differ."; + delete result; throw WriterException(message.c_str()); }