bool chunk_offsets_malloced = false;
bool ubuf_malloced = false;
bool cbuf_malloced = false;
- struct wimlib_decompressor *decompressor;
+ struct wimlib_decompressor *decompressor = NULL;
/* Sanity checks */
wimlib_assert(rspec != NULL);
ERROR("Invalid chunk size in compressed resource!");
errno = EINVAL;
ret = WIMLIB_ERR_DECOMPRESSION;
- goto out_save_decompressor;
+ goto out_free_memory;
}
if (rspec->is_pipable)
cur_read_offset += sizeof(struct pwm_chunk_hdr);
ERROR("Failed to decompress data!");
ret = WIMLIB_ERR_DECOMPRESSION;
errno = EINVAL;
- goto out_save_decompressor;
+ goto out_free_memory;
}
}
cur_read_offset += chunk_csize;
ret = (*cb)(&ubuf[start], size, cb_ctx);
if (ret)
- goto out_save_decompressor;
+ goto out_free_memory;
cur_range_pos += size;
if (cur_range_pos == cur_range_end) {
goto read_error;
}
ret = 0;
-out_save_decompressor:
- wimlib_free_decompressor(rspec->wim->decompressor);
- rspec->wim->decompressor = decompressor;
- rspec->wim->decompressor_ctype = ctype;
- rspec->wim->decompressor_max_block_size = chunk_size;
+
out_free_memory:
errno_save = errno;
+ if (decompressor) {
+ wimlib_free_decompressor(rspec->wim->decompressor);
+ rspec->wim->decompressor = decompressor;
+ rspec->wim->decompressor_ctype = ctype;
+ rspec->wim->decompressor_max_block_size = chunk_size;
+ }
if (chunk_offsets_malloced)
FREE(chunk_offsets);
if (ubuf_malloced)
if (ctx->cur_stream_offset == ctx->cur_stream->size) {
/* Finished reading all the data for a stream. */
+ ctx->cur_stream_offset = 0;
+
DEBUG("End stream (size=%"PRIu64").", ctx->cur_stream->size);
ret = (*ctx->cbs.end_stream)(ctx->cur_stream, 0,
ctx->cbs.end_stream_ctx);
else
ctx->next_stream = NULL;
}
- ctx->cur_stream_offset = 0;
}
return 0;
}