aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorYunchih Chen <yunchih.cat@gmail.com>2018-03-18 11:58:56 +0800
committerYunchih Chen <yunchih.cat@gmail.com>2018-03-18 11:59:26 +0800
commit2bf88e23cd67c7a8857611a4536ee9cabaf0a460 (patch)
tree0e6f865f9674a273e079ecd948c98d5c23e81ed5 /lib
parent3bff5a92132a97e872f7cdf1d2e26f26ccce772c (diff)
downloadnfcollect-2bf88e23cd67c7a8857611a4536ee9cabaf0a460.tar
nfcollect-2bf88e23cd67c7a8857611a4536ee9cabaf0a460.tar.gz
nfcollect-2bf88e23cd67c7a8857611a4536ee9cabaf0a460.tar.bz2
nfcollect-2bf88e23cd67c7a8857611a4536ee9cabaf0a460.tar.lz
nfcollect-2bf88e23cd67c7a8857611a4536ee9cabaf0a460.tar.xz
nfcollect-2bf88e23cd67c7a8857611a4536ee9cabaf0a460.tar.zst
nfcollect-2bf88e23cd67c7a8857611a4536ee9cabaf0a460.zip
Fix extract worker bug
Diffstat (limited to 'lib')
-rw-r--r--lib/extract.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/extract.c b/lib/extract.c
index 07050a1..9fd2496 100644
--- a/lib/extract.c
+++ b/lib/extract.c
@@ -64,35 +64,34 @@ static int nfl_extract_lz4(FILE *f, nflog_state_t *state) {
int nfl_extract_worker(const char *filename, nflog_state_t *state) {
FILE *f;
int got = 0, ret = 0;
- nflog_header_t **header = &state->header;
- nflog_entry_t **store = &state->store;
+ nflog_header_t *h;
debug("Extracting from file %s", filename);
ERR((f = fopen(filename, "rb")) == NULL, "extract worker");
- ERR(nfl_check_file(f) < 0, "extract worker");
+ /* ERR(nfl_check_file(f) < 0, "extract worker"); */
// Read header
- ERR(!(*header = malloc(sizeof(nflog_header_t))), NULL);
- got = fread(*header, 1, sizeof(nflog_header_t), f);
+ ERR(!(state->header = malloc(sizeof(nflog_header_t))), "extract malloc header");
+ got = fread(state->header, sizeof(nflog_header_t), 1, f);
+ h = state->header;
// Check header validity
WARN_RETURN(ferror(f), "%s", strerror(errno));
- WARN_RETURN(got != sizeof(nflog_header_t) || nfl_verify_header(*header) < 0,
- "File %s has corrupted header.", filename);
+ WARN_RETURN(!got || nfl_verify_header(h) < 0, "File %s has corrupted header.", filename);
// Read body
- ERR((*store = malloc(sizeof(nflog_entry_t) * (*header)->n_entries)), NULL);
- switch((*header)->compression_opt) {
+ ERR(!(state->store = malloc(sizeof(nflog_entry_t) * h->n_entries)), "extract malloc store");
+ switch(h->compression_opt) {
case COMPRESS_NONE:
- debug("Extract worker #%u: extract without compression\n", (*header)->id)
+ debug("Extract worker #%u: extract without compression\n", h->id)
nfl_extract_default(f, state);
break;
case COMPRESS_LZ4:
- debug("Extract worker #%u: extract with compression algorithm: lz4", (*header)->id)
+ debug("Extract worker #%u: extract with compression algorithm: lz4", h->id)
nfl_extract_lz4(f, state);
break;
case COMPRESS_ZSTD:
- debug("Extract worker #%u: extract with compression algorithm: zstd", (*header)->id)
+ debug("Extract worker #%u: extract with compression algorithm: zstd", h->id)
nfl_extract_zstd(f, state);
break;
// Must not reach here ...