thiru-mg commented on code in PR #3457:
URL: https://github.com/apache/avro/pull/3457#discussion_r2297177136
##########
lang/c++/impl/DataFile.cc:
##########
@@ -491,22 +492,39 @@ void DataFileReaderBase::readDataBlock() {
if (decompressed_size == ZSTD_CONTENTSIZE_ERROR) {
throw Exception("ZSTD: Not a valid compressed frame");
} else if (decompressed_size == ZSTD_CONTENTSIZE_UNKNOWN) {
- throw Exception("ZSTD: Unable to determine decompressed size");
- }
-
- // Decompress the data
- uncompressed.clear();
- uncompressed.resize(decompressed_size);
- size_t result = ZSTD_decompress(
- uncompressed.data(), decompressed_size,
- reinterpret_cast<const char *>(compressed_.data()),
compressed_.size());
-
- if (ZSTD_isError(result)) {
- throw Exception("ZSTD decompression error: {}",
ZSTD_getErrorName(result));
- }
- if (result != decompressed_size) {
- throw Exception("ZSTD: Decompressed size mismatch: expected {},
got {}",
- decompressed_size, result);
+ // Stream decompress the data
+ ZSTD_DCtx *dctx = ZSTD_createDCtx();
Review Comment:
Using bald pointers like this could lead to leaks. In fact, if this code
throws at line 498, this pointer will leak. Please define a smart pointer, say,
ZstdPtr that automatically frees the underlying pointer on destruction (RAII
pattern). In fact, we can do a thin C++ wrapper for ZSTD library and remove
most of the C like code below.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]