Skip to content

Commit 19ce250

Browse files
author
Lukas Sismis
committed
logging: prevent double-free multi-threaded logging
When multithreaded output was enabled, all threads freed shallow-copy of sensor and prefix names. This commit adds a guard so that only the parent frees the allocated buffers. Ticket: 8861
1 parent 389700e commit 19ce250

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/util-logopenfile.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -983,17 +983,20 @@ int LogFileFreeCtx(LogFileCtx *lf_ctx)
983983
SCMutexDestroy(&lf_ctx->fp_mutex);
984984
}
985985

986-
if (lf_ctx->prefix != NULL) {
987-
SCFree(lf_ctx->prefix);
988-
lf_ctx->prefix_len = 0;
986+
if (lf_ctx->parent == NULL) {
987+
if (lf_ctx->prefix != NULL) {
988+
SCFree(lf_ctx->prefix);
989+
lf_ctx->prefix_len = 0;
990+
}
991+
992+
if (lf_ctx->sensor_name != NULL) {
993+
SCFree(lf_ctx->sensor_name);
994+
}
989995
}
990996

991997
if(lf_ctx->filename != NULL)
992998
SCFree(lf_ctx->filename);
993999

994-
if (lf_ctx->sensor_name)
995-
SCFree(lf_ctx->sensor_name);
996-
9971000
if (!lf_ctx->threaded) {
9981001
OutputUnregisterFileRotationFlag(&lf_ctx->rotation_flag);
9991002
}

0 commit comments

Comments
 (0)