Free allocated memory before throwing exceptions

This commit is contained in:
Dmitry Gerasimov 2020-02-14 14:27:45 +03:00
parent 74046dac7d
commit 30c599079a
3 changed files with 3 additions and 0 deletions

View File

@ -404,6 +404,7 @@ void DecodedBitStreamParser::decodeBase256Segment(Ref<BitSource> 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++);

View File

@ -229,6 +229,7 @@ void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> 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);

View File

@ -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());
}