Commit 0e1c1099 authored by Olivier Crête's avatar Olivier Crête

conncheck: Use g_slist_free_full() for conncheck list

Skips one iterator over g_slist_foreach() + g_slist_free(). It is also easier
to read.
parent d04efdb7
...@@ -71,7 +71,7 @@ static size_t priv_create_username (NiceAgent *agent, Stream *stream, ...@@ -71,7 +71,7 @@ static size_t priv_create_username (NiceAgent *agent, Stream *stream,
uint8_t *dest, guint dest_len, gboolean inbound); uint8_t *dest, guint dest_len, gboolean inbound);
static size_t priv_get_password (NiceAgent *agent, Stream *stream, static size_t priv_get_password (NiceAgent *agent, Stream *stream,
NiceCandidate *remote, uint8_t **password); NiceCandidate *remote, uint8_t **password);
static void conn_check_free_item (gpointer data, gpointer user_data); static void conn_check_free_item (gpointer data);
static int priv_timer_expired (GTimeVal *timer, GTimeVal *now) static int priv_timer_expired (GTimeVal *timer, GTimeVal *now)
{ {
...@@ -1089,8 +1089,7 @@ static GSList *priv_limit_conn_check_list_size (GSList *conncheck_list, guint up ...@@ -1089,8 +1089,7 @@ static GSList *priv_limit_conn_check_list_size (GSList *conncheck_list, guint up
c = list_len - upper_limit; c = list_len - upper_limit;
if (c == list_len) { if (c == list_len) {
/* case: delete whole list */ /* case: delete whole list */
g_slist_foreach (conncheck_list, conn_check_free_item, NULL); g_slist_free_full (conncheck_list, conn_check_free_item);
g_slist_free (conncheck_list),
result = NULL; result = NULL;
} }
else { else {
...@@ -1103,11 +1102,8 @@ static GSList *priv_limit_conn_check_list_size (GSList *conncheck_list, guint up ...@@ -1103,11 +1102,8 @@ static GSList *priv_limit_conn_check_list_size (GSList *conncheck_list, guint up
tmp = i->next; tmp = i->next;
i->next = NULL; i->next = NULL;
if (tmp) {
/* delete the rest of the connectivity check list */ /* delete the rest of the connectivity check list */
g_slist_foreach (tmp, conn_check_free_item, NULL); g_slist_free_full (tmp, conn_check_free_item);
g_slist_free (tmp);
}
} }
} }
...@@ -1396,12 +1392,12 @@ int conn_check_add_for_local_candidate (NiceAgent *agent, guint stream_id, Compo ...@@ -1396,12 +1392,12 @@ int conn_check_add_for_local_candidate (NiceAgent *agent, guint stream_id, Compo
/* /*
* Frees the CandidateCheckPair structure pointer to * Frees the CandidateCheckPair structure pointer to
* by 'user data'. Compatible with g_slist_foreach(). * by 'user data'. Compatible with GDestroyNotify.
*/ */
static void conn_check_free_item (gpointer data, gpointer user_data) static void conn_check_free_item (gpointer data)
{ {
CandidateCheckPair *pair = data; CandidateCheckPair *pair = data;
g_assert (user_data == NULL);
pair->stun_message.buffer = NULL; pair->stun_message.buffer = NULL;
pair->stun_message.buffer_len = 0; pair->stun_message.buffer_len = 0;
g_slice_free (CandidateCheckPair, pair); g_slice_free (CandidateCheckPair, pair);
...@@ -1428,12 +1424,9 @@ void conn_check_free (NiceAgent *agent) ...@@ -1428,12 +1424,9 @@ void conn_check_free (NiceAgent *agent)
Stream *stream = i->data; Stream *stream = i->data;
nice_debug ("Agent %p, freeing conncheck_list of stream %p", agent, stream); nice_debug ("Agent %p, freeing conncheck_list of stream %p", agent, stream);
if (stream->conncheck_list) { g_slist_free_full (stream->conncheck_list, conn_check_free_item);
g_slist_foreach (stream->conncheck_list, conn_check_free_item, NULL);
g_slist_free (stream->conncheck_list),
stream->conncheck_list = NULL; stream->conncheck_list = NULL;
} }
}
conn_check_stop (agent); conn_check_stop (agent);
} }
...@@ -1446,23 +1439,11 @@ void conn_check_free (NiceAgent *agent) ...@@ -1446,23 +1439,11 @@ void conn_check_free (NiceAgent *agent)
*/ */
void conn_check_prune_stream (NiceAgent *agent, Stream *stream) void conn_check_prune_stream (NiceAgent *agent, Stream *stream)
{ {
CandidateCheckPair *pair;
GSList *i; GSList *i;
gboolean keep_going = FALSE; gboolean keep_going = FALSE;
for (i = stream->conncheck_list; i ; ) { g_slist_free_full (stream->conncheck_list, conn_check_free_item);
GSList *next = i->next; stream->conncheck_list = NULL;
pair = i->data;
g_assert (pair->stream_id == stream->id);
stream->conncheck_list =
g_slist_remove (stream->conncheck_list, pair);
conn_check_free_item (pair, NULL);
i = next;
if (!stream->conncheck_list)
break;
}
for (i = agent->streams; i; i = i->next) { for (i = agent->streams; i; i = i->next) {
Stream *s = i->data; Stream *s = i->data;
......
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