diff --git a/src/io/serialize.c b/src/io/serialize.c index 4e31b10..ebc5644 100644 --- a/src/io/serialize.c +++ b/src/io/serialize.c @@ -193,6 +193,8 @@ void write_document(document_t *doc) { void thread_cleanup() { close(index_fd); + cleanup_parse(); + cleanup_font(); } diff --git a/src/parsing/media.c b/src/parsing/media.c index b168cb2..55bc522 100644 --- a/src/parsing/media.c +++ b/src/parsing/media.c @@ -113,10 +113,13 @@ static AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder, // Feed it to decoder int decode_ret = avcodec_send_packet(decoder, &avPacket); if (decode_ret != 0) { - LOG_WARNINGF(doc->filepath, + LOG_ERRORF(doc->filepath, "(media.c) avcodec_send_packet() returned error code [%d] %s", decode_ret, av_err2str(decode_ret) ) + av_frame_free(&frame); + av_packet_unref(&avPacket); + return NULL; } av_packet_unref(&avPacket); receive_ret = avcodec_receive_frame(decoder, frame); @@ -139,7 +142,7 @@ static void append_audio_meta(AVFormatContext *pFormatCtx, document_t *doc) { AVDictionaryEntry *tag = NULL; while ((tag = av_dict_get(pFormatCtx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { - char key[32]; + char key[256]; strncpy(key, tag->key, sizeof(key)); char *ptr = key; @@ -160,7 +163,8 @@ static void append_audio_meta(AVFormatContext *pFormatCtx, document_t *doc) { } __always_inline -static void append_video_meta(AVFormatContext *pFormatCtx, AVFrame *frame, document_t *doc, int include_audio_tags, int is_video) { +static void +append_video_meta(AVFormatContext *pFormatCtx, AVFrame *frame, document_t *doc, int include_audio_tags, int is_video) { if (is_video) { meta_line_t *meta_duration = malloc(sizeof(meta_line_t)); diff --git a/src/parsing/parse.c b/src/parsing/parse.c index 2347e71..f4b0d9b 100644 --- a/src/parsing/parse.c +++ b/src/parsing/parse.c @@ -37,7 +37,13 @@ void *read_all(parse_job_t *job, const char *buf, int bytes_read) { int ret = job->vfile.read(&job->vfile, full_buf + bytes_read, job->info.st_size - bytes_read); if (ret < 0) { - LOG_ERRORF(job->filepath, "read(): [%d] %s", errno, strerror(errno)) + free(full_buf); + + if (job->vfile.is_fs_file) { + LOG_ERRORF(job->filepath, "read(): [%d] %s", errno, strerror(errno)) + } else { + LOG_ERRORF(job->filepath, "(virtual) read(): [%d] %s", ret, archive_error_string(job->vfile.arc)) + } return NULL; } } @@ -92,7 +98,13 @@ void parse(void *arg) { // Get mime type with libmagic bytes_read = job->vfile.read(&job->vfile, buf, PARSE_BUF_SIZE); if (bytes_read < 0) { - LOG_WARNINGF(job->filepath, "read() Error: %s", strerror(errno)) + + if (job->vfile.is_fs_file) { + LOG_ERRORF(job->filepath, "read(): [%d] %s", errno, strerror(errno)) + } else { + LOG_ERRORF(job->filepath, "(virtual) read(): [%d] %s", bytes_read, archive_error_string(job->vfile.arc)) + } + CLOSE_FILE(job->vfile) return; } @@ -180,3 +192,9 @@ void parse(void *arg) { CLOSE_FILE(job->vfile) } + +void cleanup_parse() { + if (Magic != NULL) { + magic_close(Magic); + } +} diff --git a/src/parsing/parse.h b/src/parsing/parse.h index c7c7a5c..990961f 100644 --- a/src/parsing/parse.h +++ b/src/parsing/parse.h @@ -10,4 +10,6 @@ void fs_close(struct vfile *f); void parse(void *arg); +void cleanup_parse(); + #endif diff --git a/src/parsing/pdf.c b/src/parsing/pdf.c index 6e938c5..ed01168 100644 --- a/src/parsing/pdf.c +++ b/src/parsing/pdf.c @@ -168,7 +168,7 @@ void fill_image(fz_context *ctx, UNUSED(fz_device *dev), } } -void parse_pdf(void *buf, size_t buf_len, document_t *doc) { +void parse_pdf(const void *buf, size_t buf_len, document_t *doc) { if (buf == NULL) { return; diff --git a/src/parsing/pdf.h b/src/parsing/pdf.h index 350a900..0af1717 100644 --- a/src/parsing/pdf.h +++ b/src/parsing/pdf.h @@ -4,6 +4,6 @@ #include "src/sist.h" -void parse_pdf(void *buf, size_t buf_len, document_t *doc); +void parse_pdf(const void *buf, size_t buf_len, document_t *doc); #endif