Skip to content

Commit 9d70b9a

Browse files
committed
Change all Version* usages to Ref<Version> to avoid valrgind of reporting memory leak on static Version objects. ftylitak#155
1 parent f0a7886 commit 9d70b9a

25 files changed

+201
-200
lines changed

examples/QZXingLive/main.qml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ ApplicationWindow
119119
{
120120
timePerFrameDecode = (decodeTime + framesDecoded * timePerFrameDecode) / (framesDecoded + 1);
121121
framesDecoded++;
122-
console.log("frame finished: " + succeeded, decodeTime, timePerFrameDecode, framesDecoded);
122+
if(succeeded)
123+
console.log("frame finished: " + succeeded, decodeTime, timePerFrameDecode, framesDecoded);
123124
}
124125
}
125126

src/zxing/zxing/datamatrix/DataMatrixVersion.cpp

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ECBlocks::~ECBlocks() {
6161
}
6262
}
6363

64-
vector<Version*> Version::VERSIONS;
64+
vector<Ref<Version>> Version::VERSIONS;
6565
static int N_VERSIONS = Version::buildVersions();
6666

6767
Version::Version(int versionNumber, int symbolSizeRows, int symbolSizeColumns, int dataRegionSizeRows,
@@ -112,7 +112,7 @@ ECBlocks* Version::getECBlocks() const {
112112
return ecBlocks_;
113113
}
114114

115-
Version* Version::getVersionForDimensions(int numRows, int numColumns) {
115+
Ref<Version> Version::getVersionForDimensions(int numRows, int numColumns) {
116116
if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) {
117117
throw ReaderException("Number of rows and columns must be even");
118118
}
@@ -121,7 +121,7 @@ Version* Version::getVersionForDimensions(int numRows, int numColumns) {
121121
// If we interleave the rectangular versions with the square versions we could
122122
// do a binary search.
123123
for (int i = 0; i < N_VERSIONS; ++i){
124-
Version* version = VERSIONS[i];
124+
Ref<Version> version = VERSIONS[i];
125125
if (version->getSymbolSizeRows() == numRows && version->getSymbolSizeColumns() == numColumns) {
126126
return version;
127127
}
@@ -133,66 +133,66 @@ Version* Version::getVersionForDimensions(int numRows, int numColumns) {
133133
* See ISO 16022:2006 5.5.1 Table 7
134134
*/
135135
int Version::buildVersions() {
136-
VERSIONS.push_back(new Version(1, 10, 10, 8, 8,
137-
new ECBlocks(5, new ECB(1, 3))));
138-
VERSIONS.push_back(new Version(2, 12, 12, 10, 10,
139-
new ECBlocks(7, new ECB(1, 5))));
140-
VERSIONS.push_back(new Version(3, 14, 14, 12, 12,
141-
new ECBlocks(10, new ECB(1, 8))));
142-
VERSIONS.push_back(new Version(4, 16, 16, 14, 14,
143-
new ECBlocks(12, new ECB(1, 12))));
144-
VERSIONS.push_back(new Version(5, 18, 18, 16, 16,
145-
new ECBlocks(14, new ECB(1, 18))));
146-
VERSIONS.push_back(new Version(6, 20, 20, 18, 18,
147-
new ECBlocks(18, new ECB(1, 22))));
148-
VERSIONS.push_back(new Version(7, 22, 22, 20, 20,
149-
new ECBlocks(20, new ECB(1, 30))));
150-
VERSIONS.push_back(new Version(8, 24, 24, 22, 22,
151-
new ECBlocks(24, new ECB(1, 36))));
152-
VERSIONS.push_back(new Version(9, 26, 26, 24, 24,
153-
new ECBlocks(28, new ECB(1, 44))));
154-
VERSIONS.push_back(new Version(10, 32, 32, 14, 14,
155-
new ECBlocks(36, new ECB(1, 62))));
156-
VERSIONS.push_back(new Version(11, 36, 36, 16, 16,
157-
new ECBlocks(42, new ECB(1, 86))));
158-
VERSIONS.push_back(new Version(12, 40, 40, 18, 18,
159-
new ECBlocks(48, new ECB(1, 114))));
160-
VERSIONS.push_back(new Version(13, 44, 44, 20, 20,
161-
new ECBlocks(56, new ECB(1, 144))));
162-
VERSIONS.push_back(new Version(14, 48, 48, 22, 22,
163-
new ECBlocks(68, new ECB(1, 174))));
164-
VERSIONS.push_back(new Version(15, 52, 52, 24, 24,
165-
new ECBlocks(42, new ECB(2, 102))));
166-
VERSIONS.push_back(new Version(16, 64, 64, 14, 14,
167-
new ECBlocks(56, new ECB(2, 140))));
168-
VERSIONS.push_back(new Version(17, 72, 72, 16, 16,
169-
new ECBlocks(36, new ECB(4, 92))));
170-
VERSIONS.push_back(new Version(18, 80, 80, 18, 18,
171-
new ECBlocks(48, new ECB(4, 114))));
172-
VERSIONS.push_back(new Version(19, 88, 88, 20, 20,
173-
new ECBlocks(56, new ECB(4, 144))));
174-
VERSIONS.push_back(new Version(20, 96, 96, 22, 22,
175-
new ECBlocks(68, new ECB(4, 174))));
176-
VERSIONS.push_back(new Version(21, 104, 104, 24, 24,
177-
new ECBlocks(56, new ECB(6, 136))));
178-
VERSIONS.push_back(new Version(22, 120, 120, 18, 18,
179-
new ECBlocks(68, new ECB(6, 175))));
180-
VERSIONS.push_back(new Version(23, 132, 132, 20, 20,
181-
new ECBlocks(62, new ECB(8, 163))));
182-
VERSIONS.push_back(new Version(24, 144, 144, 22, 22,
183-
new ECBlocks(62, new ECB(8, 156), new ECB(2, 155))));
184-
VERSIONS.push_back(new Version(25, 8, 18, 6, 16,
185-
new ECBlocks(7, new ECB(1, 5))));
186-
VERSIONS.push_back(new Version(26, 8, 32, 6, 14,
187-
new ECBlocks(11, new ECB(1, 10))));
188-
VERSIONS.push_back(new Version(27, 12, 26, 10, 24,
189-
new ECBlocks(14, new ECB(1, 16))));
190-
VERSIONS.push_back(new Version(28, 12, 36, 10, 16,
191-
new ECBlocks(18, new ECB(1, 22))));
192-
VERSIONS.push_back(new Version(29, 16, 36, 14, 16,
193-
new ECBlocks(24, new ECB(1, 32))));
194-
VERSIONS.push_back(new Version(30, 16, 48, 14, 22,
195-
new ECBlocks(28, new ECB(1, 49))));
136+
VERSIONS.push_back(Ref<Version>(new Version(1, 10, 10, 8, 8,
137+
new ECBlocks(5, new ECB(1, 3)))));
138+
VERSIONS.push_back(Ref<Version>(new Version(2, 12, 12, 10, 10,
139+
new ECBlocks(7, new ECB(1, 5)))));
140+
VERSIONS.push_back(Ref<Version>(new Version(3, 14, 14, 12, 12,
141+
new ECBlocks(10, new ECB(1, 8)))));
142+
VERSIONS.push_back(Ref<Version>(new Version(4, 16, 16, 14, 14,
143+
new ECBlocks(12, new ECB(1, 12)))));
144+
VERSIONS.push_back(Ref<Version>(new Version(5, 18, 18, 16, 16,
145+
new ECBlocks(14, new ECB(1, 18)))));
146+
VERSIONS.push_back(Ref<Version>(new Version(6, 20, 20, 18, 18,
147+
new ECBlocks(18, new ECB(1, 22)))));
148+
VERSIONS.push_back(Ref<Version>(new Version(7, 22, 22, 20, 20,
149+
new ECBlocks(20, new ECB(1, 30)))));
150+
VERSIONS.push_back(Ref<Version>(new Version(8, 24, 24, 22, 22,
151+
new ECBlocks(24, new ECB(1, 36)))));
152+
VERSIONS.push_back(Ref<Version>(new Version(9, 26, 26, 24, 24,
153+
new ECBlocks(28, new ECB(1, 44)))));
154+
VERSIONS.push_back(Ref<Version>(new Version(10, 32, 32, 14, 14,
155+
new ECBlocks(36, new ECB(1, 62)))));
156+
VERSIONS.push_back(Ref<Version>(new Version(11, 36, 36, 16, 16,
157+
new ECBlocks(42, new ECB(1, 86)))));
158+
VERSIONS.push_back(Ref<Version>(new Version(12, 40, 40, 18, 18,
159+
new ECBlocks(48, new ECB(1, 114)))));
160+
VERSIONS.push_back(Ref<Version>(new Version(13, 44, 44, 20, 20,
161+
new ECBlocks(56, new ECB(1, 144)))));
162+
VERSIONS.push_back(Ref<Version>(new Version(14, 48, 48, 22, 22,
163+
new ECBlocks(68, new ECB(1, 174)))));
164+
VERSIONS.push_back(Ref<Version>(new Version(15, 52, 52, 24, 24,
165+
new ECBlocks(42, new ECB(2, 102)))));
166+
VERSIONS.push_back(Ref<Version>(new Version(16, 64, 64, 14, 14,
167+
new ECBlocks(56, new ECB(2, 140)))));
168+
VERSIONS.push_back(Ref<Version>(new Version(17, 72, 72, 16, 16,
169+
new ECBlocks(36, new ECB(4, 92)))));
170+
VERSIONS.push_back(Ref<Version>(new Version(18, 80, 80, 18, 18,
171+
new ECBlocks(48, new ECB(4, 114)))));
172+
VERSIONS.push_back(Ref<Version>(new Version(19, 88, 88, 20, 20,
173+
new ECBlocks(56, new ECB(4, 144)))));
174+
VERSIONS.push_back(Ref<Version>(new Version(20, 96, 96, 22, 22,
175+
new ECBlocks(68, new ECB(4, 174)))));
176+
VERSIONS.push_back(Ref<Version>(new Version(21, 104, 104, 24, 24,
177+
new ECBlocks(56, new ECB(6, 136)))));
178+
VERSIONS.push_back(Ref<Version>(new Version(22, 120, 120, 18, 18,
179+
new ECBlocks(68, new ECB(6, 175)))));
180+
VERSIONS.push_back(Ref<Version>(new Version(23, 132, 132, 20, 20,
181+
new ECBlocks(62, new ECB(8, 163)))));
182+
VERSIONS.push_back(Ref<Version>(new Version(24, 144, 144, 22, 22,
183+
new ECBlocks(62, new ECB(8, 156), new ECB(2, 155)))));
184+
VERSIONS.push_back(Ref<Version>(new Version(25, 8, 18, 6, 16,
185+
new ECBlocks(7, new ECB(1, 5)))));
186+
VERSIONS.push_back(Ref<Version>(new Version(26, 8, 32, 6, 14,
187+
new ECBlocks(11, new ECB(1, 10)))));
188+
VERSIONS.push_back(Ref<Version>(new Version(27, 12, 26, 10, 24,
189+
new ECBlocks(14, new ECB(1, 16)))));
190+
VERSIONS.push_back(Ref<Version>(new Version(28, 12, 36, 10, 16,
191+
new ECBlocks(18, new ECB(1, 22)))));
192+
VERSIONS.push_back(Ref<Version>(new Version(29, 16, 36, 14, 16,
193+
new ECBlocks(24, new ECB(1, 32)))));
194+
VERSIONS.push_back(Ref<Version>(new Version(30, 16, 48, 14, 22,
195+
new ECBlocks(28, new ECB(1, 49)))));
196196
return int(VERSIONS.size());
197197
}
198198
}

src/zxing/zxing/datamatrix/Version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Version : public Counted {
6464
int dataRegionSizeColumns, ECBlocks *ecBlocks);
6565

6666
public:
67-
static std::vector<Version*> VERSIONS;
67+
static std::vector<Ref<Version>> VERSIONS;
6868

6969
~Version();
7070
int getVersionNumber() const;
@@ -75,7 +75,7 @@ class Version : public Counted {
7575
int getTotalCodewords() const;
7676
ECBlocks* getECBlocks() const;
7777
static int buildVersions();
78-
Version *getVersionForDimensions(int numRows, int numColumns);
78+
Ref<Version>getVersionForDimensions(int numRows, int numColumns);
7979

8080
private:
8181
Version(const Version&);

src/zxing/zxing/datamatrix/decoder/BitMatrixParser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ namespace datamatrix {
3333
class BitMatrixParser : public Counted {
3434
private:
3535
Ref<BitMatrix> bitMatrix_;
36-
Version* parsedVersion_;
36+
Ref<Version> parsedVersion_;
3737
Ref<BitMatrix> readBitMatrix_;
3838

3939
int copyBit(size_t x, size_t y, int versionBits);
4040

4141
public:
4242
BitMatrixParser(Ref<BitMatrix> bitMatrix);
43-
Version* readVersion(Ref<BitMatrix> bitMatrix);
43+
Ref<Version> readVersion(Ref<BitMatrix> bitMatrix);
4444
ArrayRef<zxing::byte> readCodewords();
4545
bool readModule(int row, int column, int numRows, int numColumns);
4646

src/zxing/zxing/datamatrix/decoder/DataBlock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DataBlock : public Counted {
3737
DataBlock(int numDataCodewords, ArrayRef<zxing::byte> codewords);
3838

3939
public:
40-
static std::vector<Ref<DataBlock> > getDataBlocks(ArrayRef<zxing::byte> rawCodewords, Version *version);
40+
static std::vector<Ref<DataBlock> > getDataBlocks(ArrayRef<zxing::byte> rawCodewords, Ref<Version>version);
4141

4242
int getNumDataCodewords();
4343
ArrayRef<zxing::byte> getCodewords();

src/zxing/zxing/datamatrix/decoder/DataMatrixBitMatrixParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ BitMatrixParser::BitMatrixParser(Ref<BitMatrix> bitMatrix) : bitMatrix_(NULL),
4242
readBitMatrix_ = new BitMatrix(bitMatrix_->getWidth(), bitMatrix_->getHeight());
4343
}
4444

45-
Version* BitMatrixParser::readVersion(Ref<BitMatrix> bitMatrix) {
45+
Ref<Version> BitMatrixParser::readVersion(Ref<BitMatrix> bitMatrix) {
4646
if (parsedVersion_ != 0) {
4747
return parsedVersion_;
4848
}
4949

5050
int numRows = bitMatrix->getHeight();
5151
int numColumns = bitMatrix->getWidth();
5252

53-
Version* version = parsedVersion_->getVersionForDimensions(numRows, numColumns);
53+
Ref<Version> version = parsedVersion_->getVersionForDimensions(numRows, numColumns);
5454
if (version != 0) {
5555
return version;
5656
}

src/zxing/zxing/datamatrix/decoder/DataMatrixDataBlock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ArrayRef<zxing::byte> DataBlock::getCodewords() {
3838
return codewords_;
3939
}
4040

41-
std::vector<Ref<DataBlock> > DataBlock::getDataBlocks(ArrayRef<zxing::byte> rawCodewords, Version *version) {
41+
std::vector<Ref<DataBlock> > DataBlock::getDataBlocks(ArrayRef<zxing::byte> rawCodewords, Ref<Version>version) {
4242
// Figure out the number and size of data blocks used by this version and
4343
// error correction level
4444
ECBlocks* ecBlocks = version->getECBlocks();

src/zxing/zxing/datamatrix/decoder/DataMatrixDecoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void Decoder::correctErrors(ArrayRef<zxing::byte> codewordBytes, int numDataCode
6565
Ref<DecoderResult> Decoder::decode(Ref<BitMatrix> bits) {
6666
// Construct a parser and read version, error-correction level
6767
BitMatrixParser parser(bits);
68-
Version *version = parser.readVersion(bits);
68+
Ref<Version>version = parser.readVersion(bits);
6969

7070
// Read codewords
7171
ArrayRef<zxing::byte> codewords(parser.readCodewords());

0 commit comments

Comments
 (0)