From 11ea8ab016c0892a5ba9627b36d32fad4777f84d Mon Sep 17 00:00:00 2001 From: Vikman Fernandez-Castro Date: Wed, 14 Aug 2024 13:23:13 +0200 Subject: [PATCH] fix(logcollector): do not free hash context from null file status --- src/modules/logcollector/src/logcollector.c | 22 ++++++++------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/modules/logcollector/src/logcollector.c b/src/modules/logcollector/src/logcollector.c index 3775e4ccbe..aa9026d2ba 100644 --- a/src/modules/logcollector/src/logcollector.c +++ b/src/modules/logcollector/src/logcollector.c @@ -578,8 +578,7 @@ void LogCollectorStart() if (reload_file(current) == -1) { minfo(FORGET_FILE, current->file); os_file_status_t * old_file_status = OSHash_Delete_ex(files_status, current->file); - EVP_MD_CTX_free(old_file_status->context); - os_free(old_file_status); + free_files_status_data(old_file_status); w_logcollector_state_delete_file(current->file); current->exists = 0; current->ign++; @@ -654,8 +653,7 @@ void LogCollectorStart() if(current->exists==1){ minfo(FORGET_FILE, current->file); os_file_status_t * old_file_status = OSHash_Delete_ex(files_status, current->file); - EVP_MD_CTX_free(old_file_status->context); - os_free(old_file_status); + free_files_status_data(old_file_status); w_logcollector_state_delete_file(current->file); current->exists = 0; } @@ -711,8 +709,7 @@ void LogCollectorStart() if(current->exists==1){ minfo(FORGET_FILE, current->file); os_file_status_t * old_file_status = OSHash_Delete_ex(files_status, current->file); - EVP_MD_CTX_free(old_file_status->context); - os_free(old_file_status); + free_files_status_data(old_file_status); w_logcollector_state_delete_file(current->file); current->exists = 0; } @@ -756,8 +753,7 @@ void LogCollectorStart() current->file); os_file_status_t * old_file_status = OSHash_Delete_ex(files_status, current->file); - EVP_MD_CTX_free(old_file_status->context); - os_free(old_file_status); + free_files_status_data(old_file_status); w_logcollector_state_delete_file(current->file); fclose(current->fp); @@ -791,8 +787,7 @@ void LogCollectorStart() /* Get new file */ os_file_status_t * old_file_status = OSHash_Delete_ex(files_status, current->file); - EVP_MD_CTX_free(old_file_status->context); - os_free(old_file_status); + free_files_status_data(old_file_status); w_logcollector_state_delete_file(current->file); fclose(current->fp); @@ -887,8 +882,7 @@ void LogCollectorStart() if (!PathFileExists(current->file)) { #endif os_file_status_t * old_file_status = OSHash_Delete_ex(files_status, current->file); - EVP_MD_CTX_free(old_file_status->context); - os_free(old_file_status); + free_files_status_data(old_file_status); w_logcollector_state_delete_file(current->file); if (Remove_Localfile(&(globs[j].gfiles), i, 1, 0,&globs[j])) { @@ -1026,7 +1020,7 @@ int handle_file(int i, int j, __attribute__((unused)) int do_fseek, int do_log) /* We must be able to open the file, fseek and get the * time of change from it. */ - + /* TODO: Support text mode on Windows */ lf->fp = wfopen(lf->file, "rb"); if (!lf->fp) { @@ -1115,7 +1109,7 @@ int handle_file(int i, int j, __attribute__((unused)) int do_fseek, int do_log) /* Reload file: open after close, and restore position */ int reload_file(logreader * lf) { - + /* TODO: Support text mode on Windows */ lf->fp = wfopen(lf->file, "rb");