Fix memory leak with virtual files in parse.c

This commit is contained in:
2020-03-06 09:36:07 -05:00
parent cfdd7bdd87
commit 02fa3f02f5
6 changed files with 33 additions and 7 deletions

View File

@@ -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);
}
}