@@ -182,38 +182,43 @@ class Int64RleDecoder : public Decoder {
182182 bitpacking_num_ = current_count_;
183183 is_rle_run_ = false ;
184184 } else {
185- printf (
186- " tsfile-encoding IntRleDecoder: bit_packed_group_count %d, "
187- " smaller "
188- " than 1" ,
189- bit_packed_group_count);
185+ return common::E_DECODE_ERR;
190186 }
191- read_bit_packing_buffer (bit_packed_group_count, last_bit_packed_num);
187+ ret = read_bit_packing_buffer (bit_packed_group_count,
188+ last_bit_packed_num);
192189 return ret;
193190 }
194191
195- void read_bit_packing_buffer (int bit_packed_group_count,
196- int last_bit_packed_num) {
192+ int read_bit_packing_buffer (int bit_packed_group_count,
193+ int last_bit_packed_num) {
194+ int ret = common::E_OK;
197195 if (current_buffer_ != nullptr ) {
198196 common::mem_free (current_buffer_);
199197 }
200198 current_buffer_ = static_cast <int64_t *>(
201199 common::mem_alloc (sizeof (int64_t ) * bit_packed_group_count * 8 ,
202200 common::MOD_DECODER_OBJ));
201+ if (IS_NULL (current_buffer_)) {
202+ return common::E_OOM;
203+ }
203204 int bytes_to_read = bit_packed_group_count * bit_width_;
204205 if (bytes_to_read > (int )byte_cache_.remaining_size ()) {
205206 bytes_to_read = byte_cache_.remaining_size ();
206207 }
207208 std::vector<unsigned char > bytes (bytes_to_read);
208209
209210 for (int i = 0 ; i < bytes_to_read; i++) {
210- common::SerializationUtil::read_ui8 (bytes[i], byte_cache_);
211+ if (RET_FAIL (common::SerializationUtil::read_ui8 (bytes[i],
212+ byte_cache_))) {
213+ return ret;
214+ }
211215 }
212216
213217 // save all int values in currentBuffer
214218 packer_->unpack_all_values (
215219 bytes.data (), bytes_to_read,
216220 current_buffer_); // decode from bytes, save in currentBuffer
221+ return ret;
217222 }
218223
219224 int read_length_and_bitwidth (common::ByteStream& buffer) {
@@ -222,6 +227,9 @@ class Int64RleDecoder : public Decoder {
222227 common::SerializationUtil::read_var_uint (length_, buffer))) {
223228 return common::E_PARTIAL_READ;
224229 } else {
230+ if (tmp_buf_) {
231+ common::mem_free (tmp_buf_);
232+ }
225233 tmp_buf_ =
226234 (uint8_t *)common::mem_alloc (length_, common::MOD_DECODER_OBJ);
227235 if (tmp_buf_ == nullptr ) {
0 commit comments