From 21cf431757e2fb422872eb3866e9e9fc81d297ac Mon Sep 17 00:00:00 2001 From: Denis Pronin Date: Fri, 28 Jul 2023 01:26:22 +0300 Subject: [PATCH] correctly free thread_data options at the topmost parent process for non-threaded mode: since thread_data::eo is a pointer within shared memory between the topmost fio parent process and its children let the fio parent process set the pointer to NULL as just it frees its copy of 'eo' as memory previously allocated by means of 'malloc' meaning that each child and the parent process itself must free it for threaded mode we leave it as it has always been also we do not need to check td->io_ops for being able to free td->io in fio_options_free() Signed-off-by: Denis Pronin --- backend.c | 4 ---- ioengines.c | 3 ++- options.c | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/backend.c b/backend.c index 5f0740395..b21c36640 100644 --- a/backend.c +++ b/backend.c @@ -2494,10 +2494,7 @@ static void run_threads(struct sk_out *sk_out) strerror(ret)); } else { pid_t pid; - void *eo; dprint(FD_PROCESS, "will fork\n"); - eo = td->eo; - read_barrier(); pid = fork(); if (!pid) { int ret; @@ -2506,7 +2503,6 @@ static void run_threads(struct sk_out *sk_out) _exit(ret); } else if (__td_index == fio_debug_jobno) *fio_debug_jobp = pid; - free(eo); free(fd); fd = NULL; } diff --git a/ioengines.c b/ioengines.c index 361727250..fd8c9d1a6 100644 --- a/ioengines.c +++ b/ioengines.c @@ -238,7 +238,8 @@ void free_ioengine(struct thread_data *td) if (td->eo && td->io_ops->options) { options_free(td->io_ops->options, td->eo); free(td->eo); - td->eo = NULL; + if (td->o.use_thread) + td->eo = NULL; } if (td->io_ops->dlhandle) { diff --git a/options.c b/options.c index 48aa0d7b1..9432a0fbd 100644 --- a/options.c +++ b/options.c @@ -5829,9 +5829,9 @@ void fio_options_free(struct thread_data *td) options_free(fio_options, &td->o); if (td->eo && td->io_ops && td->io_ops->options) { options_free(td->io_ops->options, td->eo); - free(td->eo); - td->eo = NULL; } + free(td->eo); + td->eo = NULL; } void fio_dump_options_free(struct thread_data *td)