Skip to content

Commit 4d875d6

Browse files
committed
Fix potential memory leak in test
1 parent c3f8a08 commit 4d875d6

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/test/TestCompressedStream.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ uint64 compress1(byte block[], uint length)
5151
delete cos;
5252
delete cis;
5353

54-
if (memcmp(&buf[0], &block[0], length) != 0)
55-
return 3;
56-
54+
uint64 res = (memcmp(&buf[0], &block[0], length) != 0) ? 3 : read ^ written;
5755
delete[] buf;
58-
return read ^ written;
56+
return res;
5957
}
6058

6159
uint64 compress2(byte block[], uint length)
@@ -103,11 +101,9 @@ uint64 compress2(byte block[], uint length)
103101
delete cos;
104102
delete cis;
105103

106-
if (memcmp(&buf[0], &block[0], length) != 0)
107-
return 3;
108-
104+
uint64 res = (memcmp(&buf[0], &block[0], length) != 0) ? 3 : read ^ written;
109105
delete[] buf;
110-
return read ^ written;
106+
return res;
111107
}
112108

113109
uint64 compress3(byte block[], uint length)
@@ -138,11 +134,9 @@ uint64 compress3(byte block[], uint length)
138134
delete cos;
139135
delete cis;
140136

141-
if (memcmp(&buf[0], &block[0], length) != 0)
142-
return 3;
143-
137+
uint64 res = (memcmp(&buf[0], &block[0], length) != 0) ? 3 : read ^ written;
144138
delete[] buf;
145-
return read ^ written;
139+
return res;
146140
}
147141

148142
uint64 compress4(byte block[], uint length)

0 commit comments

Comments
 (0)