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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6459>
This commit is contained in:
Taruntej Kanakamalla 2024-03-26 19:40:04 +05:30 committed by Tim-Philipp Müller
parent 3abc1c8c7b
commit b014650cbe

View file

@ -336,6 +336,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;
@ -2353,7 +2358,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;