From c084a99337e0c698195db24d719a8e590d450221 Mon Sep 17 00:00:00 2001 From: bnnm Date: Mon, 25 Mar 2019 21:15:14 +0100 Subject: [PATCH] Fix body_file with chunks --- src/meta/txth.c | 13 +++++++------ src/meta/txth_streamfile.h | 14 ++++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/meta/txth.c b/src/meta/txth.c index b42e12c3..9415d49a 100644 --- a/src/meta/txth.c +++ b/src/meta/txth.c @@ -652,14 +652,15 @@ static void set_body_chunk(txth_header * txth) { if (txth->chunk_number > txth->chunk_count) return; - temp_streamFile = setup_txth_streamfile(txth->streamBody, txth->chunk_start, txth->chunk_size, txth->chunk_count, txth->chunk_number - 1); + temp_streamFile = setup_txth_streamfile(txth->streamBody, txth->chunk_start, txth->chunk_size, txth->chunk_count, txth->chunk_number - 1, txth->streambody_opened); if (!temp_streamFile) return; - if (txth->streambody_opened) { - close_streamfile(txth->streamBody); - txth->streamBody = NULL; - txth->streambody_opened = 0; - } + /* closing is handled by temp_streamFile */ + //if (txth->streambody_opened) { + // close_streamfile(txth->streamBody); + // txth->streamBody = NULL; + // txth->streambody_opened = 0; + //} txth->streamBody = temp_streamFile; txth->streambody_opened = 1; diff --git a/src/meta/txth_streamfile.h b/src/meta/txth_streamfile.h index bbe4d97d..b9bfbd0d 100644 --- a/src/meta/txth_streamfile.h +++ b/src/meta/txth_streamfile.h @@ -95,7 +95,7 @@ static size_t txth_io_size(STREAMFILE *streamfile, txth_io_data* data) { } /* Handles deinterleaving of generic chunked streams */ -static STREAMFILE* setup_txth_streamfile(STREAMFILE *streamFile, off_t chunk_start, size_t chunk_size, int chunk_count, int chunk_number) { +static STREAMFILE* setup_txth_streamfile(STREAMFILE *streamFile, off_t chunk_start, size_t chunk_size, int chunk_count, int chunk_number, int is_opened_streamfile) { STREAMFILE *temp_streamFile = NULL, *new_streamFile = NULL; txth_io_data io_data = {0}; size_t io_data_size = sizeof(txth_io_data); @@ -109,10 +109,16 @@ static STREAMFILE* setup_txth_streamfile(STREAMFILE *streamFile, off_t chunk_sta io_data.logical_offset = -1; /* force phys offset reset */ + new_streamFile = streamFile; + /* setup subfile */ - new_streamFile = open_wrap_streamfile(streamFile); - if (!new_streamFile) goto fail; - temp_streamFile = new_streamFile; + if (!is_opened_streamfile) { + /* if streamFile was opened by txth code we MUST close it once done (as it's now "fused"),, + * otherwise it was external to txth and must be wrapped to avoid closing it */ + new_streamFile = open_wrap_streamfile(new_streamFile); + if (!new_streamFile) goto fail; + temp_streamFile = new_streamFile; + } new_streamFile = open_io_streamfile(new_streamFile, &io_data,io_data_size, txth_io_read,txth_io_size); if (!new_streamFile) goto fail;