mirror of
				https://github.com/simon987/sist2.git
				synced 2025-11-04 01:36:51 +00:00 
			
		
		
		
	Fix memory leak with virtual files in parse.c
This commit is contained in:
		
							parent
							
								
									cfdd7bdd87
								
							
						
					
					
						commit
						02fa3f02f5
					
				@ -193,6 +193,8 @@ void write_document(document_t *doc) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void thread_cleanup() {
 | 
					void thread_cleanup() {
 | 
				
			||||||
    close(index_fd);
 | 
					    close(index_fd);
 | 
				
			||||||
 | 
					    cleanup_parse();
 | 
				
			||||||
 | 
					    cleanup_font();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -113,10 +113,13 @@ static AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder,
 | 
				
			|||||||
        // Feed it to decoder
 | 
					        // Feed it to decoder
 | 
				
			||||||
        int decode_ret = avcodec_send_packet(decoder, &avPacket);
 | 
					        int decode_ret = avcodec_send_packet(decoder, &avPacket);
 | 
				
			||||||
        if (decode_ret != 0) {
 | 
					        if (decode_ret != 0) {
 | 
				
			||||||
            LOG_WARNINGF(doc->filepath,
 | 
					            LOG_ERRORF(doc->filepath,
 | 
				
			||||||
                         "(media.c) avcodec_send_packet() returned error code [%d] %s",
 | 
					                         "(media.c) avcodec_send_packet() returned error code [%d] %s",
 | 
				
			||||||
                         decode_ret, av_err2str(decode_ret)
 | 
					                         decode_ret, av_err2str(decode_ret)
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					            av_frame_free(&frame);
 | 
				
			||||||
 | 
					            av_packet_unref(&avPacket);
 | 
				
			||||||
 | 
					            return NULL;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        av_packet_unref(&avPacket);
 | 
					        av_packet_unref(&avPacket);
 | 
				
			||||||
        receive_ret = avcodec_receive_frame(decoder, frame);
 | 
					        receive_ret = avcodec_receive_frame(decoder, frame);
 | 
				
			||||||
@ -139,7 +142,7 @@ static void append_audio_meta(AVFormatContext *pFormatCtx, document_t *doc) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    AVDictionaryEntry *tag = NULL;
 | 
					    AVDictionaryEntry *tag = NULL;
 | 
				
			||||||
    while ((tag = av_dict_get(pFormatCtx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
 | 
					    while ((tag = av_dict_get(pFormatCtx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
 | 
				
			||||||
        char key[32];
 | 
					        char key[256];
 | 
				
			||||||
        strncpy(key, tag->key, sizeof(key));
 | 
					        strncpy(key, tag->key, sizeof(key));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        char *ptr = key;
 | 
					        char *ptr = key;
 | 
				
			||||||
@ -160,7 +163,8 @@ static void append_audio_meta(AVFormatContext *pFormatCtx, document_t *doc) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
__always_inline
 | 
					__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) {
 | 
					    if (is_video) {
 | 
				
			||||||
        meta_line_t *meta_duration = malloc(sizeof(meta_line_t));
 | 
					        meta_line_t *meta_duration = malloc(sizeof(meta_line_t));
 | 
				
			||||||
 | 
				
			|||||||
@ -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);
 | 
					        int ret = job->vfile.read(&job->vfile, full_buf + bytes_read, job->info.st_size - bytes_read);
 | 
				
			||||||
        if (ret < 0) {
 | 
					        if (ret < 0) {
 | 
				
			||||||
 | 
					            free(full_buf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (job->vfile.is_fs_file) {
 | 
				
			||||||
                LOG_ERRORF(job->filepath, "read(): [%d] %s", errno, strerror(errno))
 | 
					                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;
 | 
					            return NULL;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -92,7 +98,13 @@ void parse(void *arg) {
 | 
				
			|||||||
        // Get mime type with libmagic
 | 
					        // Get mime type with libmagic
 | 
				
			||||||
        bytes_read = job->vfile.read(&job->vfile, buf, PARSE_BUF_SIZE);
 | 
					        bytes_read = job->vfile.read(&job->vfile, buf, PARSE_BUF_SIZE);
 | 
				
			||||||
        if (bytes_read < 0) {
 | 
					        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)
 | 
					            CLOSE_FILE(job->vfile)
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -180,3 +192,9 @@ void parse(void *arg) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    CLOSE_FILE(job->vfile)
 | 
					    CLOSE_FILE(job->vfile)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void cleanup_parse() {
 | 
				
			||||||
 | 
					    if (Magic != NULL) {
 | 
				
			||||||
 | 
					        magic_close(Magic);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -10,4 +10,6 @@ void fs_close(struct vfile *f);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void parse(void *arg);
 | 
					void parse(void *arg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void cleanup_parse();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
@ -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) {
 | 
					    if (buf == NULL) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,6 @@
 | 
				
			|||||||
#include "src/sist.h"
 | 
					#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
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user