From 6a67ae1bfabb9bfbc83286d59f41ef97b13e1e01 Mon Sep 17 00:00:00 2001 From: Taruntej Kanakamalla Date: Tue, 26 Mar 2024 19:40:04 +0530 Subject: [PATCH] net/gstptpclock: fix double free of domain data during deinit The attempt to free the domain data is happeing twice during the ptp deinit. Once while iterating through the list domain_data and second while iterating through the list domain_clocks, so this is crashing the application trying to gst_ptp_deinit Part-of: --- subprojects/gstreamer/libs/gst/net/gstptpclock.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/subprojects/gstreamer/libs/gst/net/gstptpclock.c b/subprojects/gstreamer/libs/gst/net/gstptpclock.c index 22c650d996..15afd4ec67 100644 --- a/subprojects/gstreamer/libs/gst/net/gstptpclock.c +++ b/subprojects/gstreamer/libs/gst/net/gstptpclock.c @@ -382,6 +382,11 @@ typedef struct GstClock *domain_clock; } PtpDomainData; +// The lists domain_clocks and domain_data are same but the former is protected +// by the domain_clocks_lock. +// It is needed because sometimes other threads than the PTP thread will need +// to access the list, and without a mutex it might happen that the original +// list (domain_data) is modified at the same time (prepending a new domain). static GList *domain_data; static GMutex domain_clocks_lock; static GList *domain_clocks; @@ -3050,7 +3055,8 @@ gst_ptp_deinit (void) } g_list_free (domain_data); domain_data = NULL; - g_list_foreach (domain_clocks, (GFunc) g_free, NULL); + // The domain_clocks list is same as domain_data + // and the elements are freed above already g_list_free (domain_clocks); domain_clocks = NULL;