Commit 1041bfd0 authored by Aaron Boxer's avatar Aaron Boxer

info: use read/write lock to protect __log_functions list

Avoid leaking list when adding a log function.
parent 3f932901
Pipeline #54495 passed with stages
in 166 minutes and 48 seconds
......@@ -281,7 +281,7 @@ typedef struct
GDestroyNotify notify;
}
LogFuncEntry;
static GMutex __log_func_mutex;
static GRWLock __log_func_rw_lock;
static GSList *__log_functions = NULL;
/* whether to add the default log function in gst_init() */
......@@ -562,6 +562,7 @@ gst_debug_log_valist (GstDebugCategory * category, GstDebugLevel level,
message.format = format;
G_VA_COPY (message.arguments, args);
g_rw_lock_reader_lock (&__log_func_rw_lock);
handler = __log_functions;
while (handler) {
entry = handler->data;
......@@ -569,6 +570,7 @@ gst_debug_log_valist (GstDebugCategory * category, GstDebugLevel level,
entry->func (category, level, file, function, line, object, &message,
entry->user_data);
}
g_rw_lock_reader_unlock (&__log_func_rw_lock);
g_free (message.message);
va_end (message.arguments);
}
......@@ -1307,7 +1309,6 @@ gst_debug_add_log_function (GstLogFunction func, gpointer user_data,
GDestroyNotify notify)
{
LogFuncEntry *entry;
GSList *list;
if (func == NULL)
func = gst_debug_log_default;
......@@ -1316,17 +1317,9 @@ gst_debug_add_log_function (GstLogFunction func, gpointer user_data,
entry->func = func;
entry->user_data = user_data;
entry->notify = notify;
/* FIXME: we leak the old list here - other threads might access it right now
* in gst_debug_logv. Another solution is to lock the mutex in gst_debug_logv,
* but that is waaay costly.
* It'd probably be clever to use some kind of RCU here, but I don't know
* anything about that.
*/
g_mutex_lock (&__log_func_mutex);
list = g_slist_copy (__log_functions);
__log_functions = g_slist_prepend (list, entry);
g_mutex_unlock (&__log_func_mutex);
g_rw_lock_writer_lock (&__log_func_rw_lock);
__log_functions = g_slist_prepend (__log_functions, entry);
g_rw_lock_writer_unlock (&__log_func_rw_lock);
if (gst_is_initialized ())
GST_DEBUG ("prepended log function %p (user data %p) to log functions",
func, user_data);
......@@ -1355,7 +1348,7 @@ gst_debug_remove_with_compare_func (GCompareFunc func, gpointer data)
GSList *new, *cleanup = NULL;
guint removals = 0;
g_mutex_lock (&__log_func_mutex);
g_rw_lock_writer_lock (&__log_func_rw_lock);
new = __log_functions;
cleanup = NULL;
while ((found = g_slist_find_custom (new, data, func))) {
......@@ -1371,7 +1364,7 @@ gst_debug_remove_with_compare_func (GCompareFunc func, gpointer data)
}
/* FIXME: We leak the old list here. See _add_log_function for why. */
__log_functions = new;
g_mutex_unlock (&__log_func_mutex);
g_rw_lock_writer_unlock (&__log_func_rw_lock);
while (cleanup) {
LogFuncEntry *entry = cleanup->data;
......@@ -2117,7 +2110,7 @@ _priv_gst_debug_cleanup (void)
}
g_mutex_unlock (&__level_name_mutex);
g_mutex_lock (&__log_func_mutex);
g_rw_lock_writer_lock (&__log_func_rw_lock);
while (__log_functions) {
LogFuncEntry *log_func_entry = __log_functions->data;
if (log_func_entry->notify)
......@@ -2125,7 +2118,7 @@ _priv_gst_debug_cleanup (void)
g_slice_free (LogFuncEntry, log_func_entry);
__log_functions = g_slist_delete_link (__log_functions, __log_functions);
}
g_mutex_unlock (&__log_func_mutex);
g_rw_lock_writer_unlock (&__log_func_rw_lock);
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment