forked from osmocom/wireshark
kafka: zstd: free the composite tvb only once
Fix the composite tvb handling for zstd decompression in the same way as we already did for lz4 and snappy. Allocate the composite tvb only if we are cetain that data will be added to it. Do not free the composite tvb ourselves, leave this to epan cleanup. Change-Id: Iac74ea6e6d220b05858a7eb267276ff983b1b2ab Reviewed-on: https://code.wireshark.org/review/37900 Reviewed-by: Martin Kaiser <wireshark@kaiser.cx> Petri-Dish: Martin Kaiser <wireshark@kaiser.cx> Tested-by: Petri Dish Buildbot Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
This commit is contained in:
parent
391d451663
commit
dc7f935330
|
@ -1504,7 +1504,7 @@ decompress_zstd(tvbuff_t *tvb, packet_info *pinfo, int offset, guint32 length, t
|
|||
ZSTD_inBuffer input = { tvb_memdup(wmem_packet_scope(), tvb, offset, length), length, 0 };
|
||||
ZSTD_DStream *zds = ZSTD_createDStream();
|
||||
size_t rc = 0;
|
||||
tvbuff_t *composite_tvb = tvb_new_composite();
|
||||
tvbuff_t *composite_tvb = NULL;
|
||||
int ret = 0;
|
||||
|
||||
do {
|
||||
|
@ -1515,21 +1515,24 @@ decompress_zstd(tvbuff_t *tvb, packet_info *pinfo, int offset, guint32 length, t
|
|||
if (ZSTD_isError(rc)) {
|
||||
goto end;
|
||||
}
|
||||
if (!composite_tvb) {
|
||||
composite_tvb = tvb_new_composite();
|
||||
}
|
||||
tvb_composite_append(composite_tvb,
|
||||
tvb_new_child_real_data(tvb, (guint8*)output.dst, (guint)output.pos, (gint)output.pos));
|
||||
// rc == 0 means there is nothing more to decompress, but there could be still something in the data
|
||||
} while (rc > 0);
|
||||
tvb_composite_finalize(composite_tvb);
|
||||
*decompressed_tvb = composite_tvb;
|
||||
*decompressed_offset = 0;
|
||||
composite_tvb = NULL;
|
||||
ret = 1;
|
||||
end:
|
||||
ZSTD_freeDStream(zds);
|
||||
if (composite_tvb != NULL) {
|
||||
tvb_free_chain(composite_tvb);
|
||||
if (composite_tvb) {
|
||||
tvb_composite_finalize(composite_tvb);
|
||||
}
|
||||
if (ret == 0) {
|
||||
ZSTD_freeDStream(zds);
|
||||
if (ret == 1) {
|
||||
*decompressed_tvb = composite_tvb;
|
||||
*decompressed_offset = 0;
|
||||
}
|
||||
else {
|
||||
col_append_str(pinfo->cinfo, COL_INFO, " [zstd decompression failed]");
|
||||
}
|
||||
return ret;
|
||||
|
|
Loading…
Reference in New Issue