[Nice] [nice/master] free candidates returned by nice_agent_get_local_candidates

Youness Alaoui youness.alaoui at collabora.co.uk
Wed Nov 12 16:59:57 PST 2008


---
 agent/test-fallback.c |    2 ++
 agent/test-fullmode.c |   22 ++++++++++++++++++++--
 agent/test-mainloop.c |    4 +++-
 agent/test-restart.c  |    2 ++
 agent/test-thread.c   |   10 ++++++++--
 agent/test.c          |    4 +++-
 6 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/agent/test-fallback.c b/agent/test-fallback.c
index 1a37a58..ef91416 100644
--- a/agent/test-fallback.c
+++ b/agent/test-fallback.c
@@ -202,6 +202,8 @@ static void priv_get_local_addr (NiceAgent *agent, guint stream_id, guint compon
       break;
     }
   }
+  for (i = cands; i; i = i->next)
+    nice_candidate_free ((NiceCandidate *) i->data);
   g_slist_free (cands);
 }
 
diff --git a/agent/test-fullmode.c b/agent/test-fullmode.c
index 70de87b..400a4ba 100644
--- a/agent/test-fullmode.c
+++ b/agent/test-fullmode.c
@@ -263,6 +263,8 @@ static void priv_get_local_addr (NiceAgent *agent, guint stream_id, guint compon
       *dstaddr = cand->addr;
     }
   }
+  for (i = cands; i; i = i->next)
+    nice_candidate_free ((NiceCandidate *) i->data);
   g_slist_free (cands);
 }
 
@@ -279,8 +281,11 @@ static GSList *priv_get_local_candidate (NiceAgent *agent, guint stream_id, guin
       out_cand = cand;
     }
   }
+  result = g_slist_append (result, nice_candidate_copy (out_cand));
+
+  for (i = cands; i; i = i->next)
+    nice_candidate_free ((NiceCandidate *) i->data);
   g_slist_free (cands);
-  result = g_slist_append (result, out_cand);
   return result;
 }
 
@@ -300,7 +305,7 @@ static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *bas
 {
   //  NiceAddress laddr, raddr, laddr_rtcp, raddr_rtcp;   
   NiceCandidate cdes;
-  GSList *cands;
+  GSList *cands, *i;
   guint ls_id, rs_id;
 
   init_candidate (&cdes);
@@ -407,15 +412,23 @@ static int run_full_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *bas
   g_slist_free (cands);*/
   cands = priv_get_local_candidate (ragent, rs_id, NICE_COMPONENT_TYPE_RTP);
   nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, cands);
+  for (i = cands; i; i = i->next)
+    nice_candidate_free ((NiceCandidate *) i->data);
   g_slist_free (cands);
   cands = priv_get_local_candidate (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP);
   nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, cands);
+  for (i = cands; i; i = i->next)
+    nice_candidate_free ((NiceCandidate *) i->data);
   g_slist_free (cands);
   cands = priv_get_local_candidate (lagent, ls_id, NICE_COMPONENT_TYPE_RTP);
   nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, cands);
+  for (i = cands; i; i = i->next)
+    nice_candidate_free ((NiceCandidate *) i->data);
   g_slist_free (cands);
   cands = priv_get_local_candidate (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP);
   nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, cands);
+  for (i = cands; i; i = i->next)
+    nice_candidate_free ((NiceCandidate *) i->data);
   g_slist_free (cands);
 
   g_debug ("test-fullmode: Set properties, next running mainloop until connectivity checks succeed...");
@@ -672,6 +685,8 @@ static int run_full_test_wrong_password (NiceAgent *lagent, NiceAgent *ragent, N
       laddr = cand->addr;
     }
   }
+  for (i = cands; i; i = i->next)
+    nice_candidate_free ((NiceCandidate *) i->data);
   g_slist_free (cands);
 
   cands = nice_agent_get_local_candidates(ragent, rs_id, NICE_COMPONENT_TYPE_RTP);
@@ -791,6 +806,8 @@ static int run_full_test_control_conflict (NiceAgent *lagent, NiceAgent *ragent,
       laddr = cand->addr;
     }
   }
+  for (i = cands; i; i = i->next)
+    nice_candidate_free ((NiceCandidate *) i->data);
   g_slist_free (cands);
 
   cands = nice_agent_get_local_candidates(ragent, rs_id, NICE_COMPONENT_TYPE_RTP);
@@ -971,6 +988,7 @@ int main (void)
   g_assert (global_lagent_cands == 2);
   g_assert (global_ragent_cands == 2);
 
+
   /* run test with incorrect credentials (make sure process fails) */
   g_debug ("test-fullmode: TEST STARTS / incorrect credentials");
   result = run_full_test_wrong_password (lagent, ragent, &baseaddr);
diff --git a/agent/test-mainloop.c b/agent/test-mainloop.c
index f2fc022..d0c7e60 100644
--- a/agent/test-mainloop.c
+++ b/agent/test-mainloop.c
@@ -87,12 +87,14 @@ main (void)
 
     {
       NiceCandidate *candidate;
-      GSList *candidates;
+      GSList *candidates, *i;
 
       candidates = nice_agent_get_local_candidates (agent, 1, 1);
       candidate = candidates->data;
 
       nice_socket_send (candidate->sockptr, &(candidate->addr), 6, "\x80hello");
+      for (i = candidates; i; i = i->next)
+        nice_candidate_free ((NiceCandidate *) i->data);
       g_slist_free (candidates);
     }
 
diff --git a/agent/test-restart.c b/agent/test-restart.c
index ae4505d..9a67481 100644
--- a/agent/test-restart.c
+++ b/agent/test-restart.c
@@ -188,6 +188,8 @@ static void priv_get_local_addr (NiceAgent *agent, guint stream_id, guint compon
       *dstaddr = cand->addr;
     }
   }
+  for (i = cands; i; i = i->next)
+    nice_candidate_free ((NiceCandidate *) i->data);
   g_slist_free (cands);
 }
 
diff --git a/agent/test-thread.c b/agent/test-thread.c
index 56b446c..21cece2 100644
--- a/agent/test-thread.c
+++ b/agent/test-thread.c
@@ -94,8 +94,8 @@ cb_new_selected_pair(NiceAgent *agent,
 static void cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpointer data)
 {
   NiceAgent *other = g_object_get_data (G_OBJECT (agent), "other-agent");
-  const gchar *ufrag = NULL, *password = NULL;
-  GSList *cands;
+  gchar *ufrag = NULL, *password = NULL;
+  GSList *cands, *i;
   guint id, other_id;
   gpointer tmp;
 
@@ -109,11 +109,17 @@ static void cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpoin
   nice_agent_get_local_credentials(agent, id, &ufrag, &password);
   nice_agent_set_remote_credentials (other,
       other_id, ufrag, password);
+  g_free (ufrag);
+  g_free (password);
 
   cands = nice_agent_get_local_candidates(agent, id, 1);
   g_assert (cands != NULL);
 
   nice_agent_set_remote_candidates (other, other_id, 1, cands);
+
+  for (i = cands; i; i = i->next)
+    nice_candidate_free ((NiceCandidate *) i->data);
+  g_slist_free (cands);
 }
 
 
diff --git a/agent/test.c b/agent/test.c
index f9904e2..a08ad54 100644
--- a/agent/test.c
+++ b/agent/test.c
@@ -49,7 +49,7 @@ main (void)
   NiceAgent *agent;
   NiceAddress addr_local, addr_remote;
   NiceCandidate *candidate;
-  GSList *candidates;
+  GSList *candidates, *i;
   guint stream_id;
 
   nice_address_init (&addr_local);
@@ -86,6 +86,8 @@ main (void)
   nice_address_set_port (&(candidate->addr), 1);
   g_assert (nice_address_equal (&(candidate->addr), &addr_local));
   g_assert (strncmp (candidate->foundation, "1", 1) == 0);
+  for (i = candidates; i; i = i->next)
+    nice_candidate_free ((NiceCandidate *) i->data);
   g_slist_free (candidates);
 
   /* clean up */
-- 
1.5.6.5




More information about the Nice mailing list