From fc3203073524de9385048e218fc2f2329ad2bdd4 Mon Sep 17 00:00:00 2001 From: Jean Le Feuvre Date: Fri, 19 Dec 2025 18:32:46 +0100 Subject: [PATCH] fixed potential race condition leading to crash in filter_remove_iternal --- src/filter_core/filter.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/filter_core/filter.c b/src/filter_core/filter.c index b23b6fa4b..0bdbd7392 100644 --- a/src/filter_core/filter.c +++ b/src/filter_core/filter.c @@ -3881,6 +3881,12 @@ void gf_filter_remove_internal(GF_Filter *filter, GF_Filter *until_filter, Bool } else { GF_LOG(GF_LOG_INFO, GF_LOG_FILTER, ("Disconnecting filter %s from session\n", filter->name)); } + //lock before the loop for multithreaded cases: + //1- gf_fs_post_disconnect_task can be called, triggering a filter_post_remove + //2- the filter_remove could be executed before we reach the end of the loop, hence crash + //By locking, we'll force filter_post_remove to wait + gf_mx_p(filter->tasks_mx); + //get all dest pids, post disconnect and mark filters as removed gf_assert(!filter->removed); filter->removed = 1; @@ -3901,7 +3907,6 @@ void gf_filter_remove_internal(GF_Filter *filter, GF_Filter *until_filter, Bool } } } - gf_mx_p(filter->tasks_mx); if (!filter->num_output_pids && !filter->num_input_pids) { gf_filter_post_remove(filter);