Skip to content

Commit

Permalink
Merge pull request #81 from wazuh/fix/25202-crash-logcollector
Browse files Browse the repository at this point in the history
Fix crash in Logcollector when rotating a log
  • Loading branch information
vikman90 authored Aug 16, 2024
2 parents e64ac9f + 11ea8ab commit 6046ab2
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/modules/logcollector/src/logcollector.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");

Expand Down

0 comments on commit 6046ab2

Please sign in to comment.