[farsight2/master] Fix leaks in upnp code

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 23 15:25:20 PST 2008


---
 gst-libs/ext/fsupnp/fs-upnp-simple-igd-thread.c |    3 +++
 gst-libs/ext/fsupnp/fs-upnp-simple-igd.c        |   22 +++++++++++++++++++---
 tests/check/transmitter/rawudp-upnp.c           |    2 ++
 tests/check/upnp/fsupnp.c                       |   11 +++++++++++
 transmitters/rawudp/fs-rawudp-component.c       |    6 ++++++
 5 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/gst-libs/ext/fsupnp/fs-upnp-simple-igd-thread.c b/gst-libs/ext/fsupnp/fs-upnp-simple-igd-thread.c
index fc56b2e..55c4a32 100644
--- a/gst-libs/ext/fsupnp/fs-upnp-simple-igd-thread.c
+++ b/gst-libs/ext/fsupnp/fs-upnp-simple-igd-thread.c
@@ -115,6 +115,7 @@ fs_upnp_simple_igd_thread_dispose (GObject *object)
     g_source_set_callback (stop_src, main_loop_quit, self->priv->loop,
         g_main_loop_unref);
     g_source_attach (stop_src, self->priv->context);
+    g_source_unref (stop_src);
     g_main_loop_quit (self->priv->loop);
   }
   self->priv->quit_loop = TRUE;
@@ -260,6 +261,7 @@ fs_upnp_simple_igd_thread_add_port (FsUpnpSimpleIgd *self,
       free_add_remove_port_data);
   g_source_set_priority (source, G_PRIORITY_DEFAULT);
   g_source_attach (source, realself->priv->context);
+  g_source_unref (source);
   g_main_context_wakeup (realself->priv->context);
 }
 
@@ -282,6 +284,7 @@ fs_upnp_simple_igd_thread_remove_port (FsUpnpSimpleIgd *self,
       free_add_remove_port_data);
   g_source_set_priority (source, G_PRIORITY_DEFAULT);
   g_source_attach (source, realself->priv->context);
+  g_source_unref (source);
   g_main_context_wakeup (realself->priv->context);
 }
 
diff --git a/gst-libs/ext/fsupnp/fs-upnp-simple-igd.c b/gst-libs/ext/fsupnp/fs-upnp-simple-igd.c
index 7b8fce3..b93e0e7 100644
--- a/gst-libs/ext/fsupnp/fs-upnp-simple-igd.c
+++ b/gst-libs/ext/fsupnp/fs-upnp-simple-igd.c
@@ -301,6 +301,12 @@ _external_ip_address_changed (GUPnPServiceProxy *proxy, const gchar *variable,
 }
 
 static void
+free_proxymapping (struct ProxyMapping *pm)
+{
+  g_slice_free (struct ProxyMapping, pm);
+}
+
+static void
 free_proxy (struct Proxy *prox)
 {
   if (prox->external_ip_action)
@@ -311,7 +317,9 @@ free_proxy (struct Proxy *prox)
 
   g_object_unref (prox->proxy);
   g_ptr_array_foreach (prox->proxymappings, (GFunc) stop_proxymapping, NULL);
+  g_ptr_array_foreach (prox->proxymappings, (GFunc) free_proxymapping, NULL);
   g_ptr_array_free (prox->proxymappings, TRUE);
+  g_free (prox->external_ip);
   g_slice_free (struct Proxy, prox);
 }
 
@@ -422,6 +430,8 @@ _cp_service_unavail (GUPnPControlPoint *cp,
     {
       g_ptr_array_foreach (prox->proxymappings, (GFunc) stop_proxymapping,
           NULL);
+      g_ptr_array_foreach (prox->proxymappings, (GFunc) free_proxymapping,
+          NULL);
       free_proxy (prox);
       g_ptr_array_remove_index_fast (self->priv->service_proxies, i);
       break;
@@ -481,7 +491,7 @@ _service_proxy_got_external_ip_address (GUPnPServiceProxy *proxy,
   g_return_if_fail (prox->external_ip_action == action);
 
   prox->external_ip_action = NULL;
-
+  
   if (gupnp_service_proxy_end_action (proxy, action, &error,
           "NewExternalIPAddress", G_TYPE_STRING, &ip,
           NULL))
@@ -500,7 +510,7 @@ _service_proxy_got_external_ip_address (GUPnPServiceProxy *proxy,
     }
 
     g_free (prox->external_ip);
-    prox->external_ip = g_strdup (ip);
+    prox->external_ip = ip;
   }
   else
   {
@@ -790,7 +800,10 @@ fs_upnp_simple_igd_remove_port_real (FsUpnpSimpleIgd *self,
         stop_proxymapping (pm);
 
         if (pm->renew_src)
+        {
           g_source_destroy (pm->renew_src);
+          g_source_unref (pm->renew_src);
+        }
         pm->renew_src = NULL;
 
         if (pm->mapped)
@@ -802,7 +815,7 @@ fs_upnp_simple_igd_remove_port_real (FsUpnpSimpleIgd *self,
               "NewProtocol", G_TYPE_STRING, mapping->protocol,
               NULL);
 
-        g_slice_free (struct ProxyMapping, pm);
+        free_proxymapping (pm);
         g_ptr_array_remove_index_fast (prox->proxymappings, j);
         j--;
       }
@@ -833,6 +846,9 @@ stop_proxymapping (struct ProxyMapping *pm)
   pm->action = NULL;
 
   if (pm->timeout_src)
+  {
     g_source_destroy (pm->timeout_src);
+    g_source_unref (pm->timeout_src);
+  }
   pm->timeout_src = NULL;
 }
diff --git a/tests/check/transmitter/rawudp-upnp.c b/tests/check/transmitter/rawudp-upnp.c
index 55df3fa..a09b0de 100644
--- a/tests/check/transmitter/rawudp-upnp.c
+++ b/tests/check/transmitter/rawudp-upnp.c
@@ -137,10 +137,12 @@ start_upnp_server (void)
   subdev2 = gupnp_device_info_get_device (subdev1,
       "urn:schemas-upnp-org:device:WANConnectionDevice:1");
   ts_fail_if (subdev2 == NULL, "Could not get WANConnectionDevice");
+  g_object_unref (subdev1);
 
   service = gupnp_device_info_get_service (subdev2,
       "urn:schemas-upnp-org:service:WANIPConnection:1");
   ts_fail_if (service == NULL, "Could not get WANIPConnection");
+  g_object_unref (subdev2);
 
   g_signal_connect (service, "action-invoked::GetExternalIPAddress",
       G_CALLBACK (get_external_ip_address_cb), NULL);
diff --git a/tests/check/upnp/fsupnp.c b/tests/check/upnp/fsupnp.c
index 69870aa..4640b29 100644
--- a/tests/check/upnp/fsupnp.c
+++ b/tests/check/upnp/fsupnp.c
@@ -93,6 +93,11 @@ add_port_mapping_cb (GUPnPService *service,
   fail_unless (desc != NULL, "no desc");
   fail_unless (lease == 10, "no lease");
 
+  g_free (remote_host);
+  g_free (proto);
+  g_free (internal_client);
+  g_free (desc);
+
   gupnp_service_action_return (action);
 }
 
@@ -118,6 +123,9 @@ delete_port_mapping_cb (GUPnPService *service,
 
   gupnp_service_action_return (action);
 
+  g_free (remote_host);
+  g_free (proto);
+
   g_main_loop_quit (loop);
 }
 
@@ -181,10 +189,12 @@ run_fsupnp_test (GMainContext *mainctx, FsUpnpSimpleIgd *igd)
   subdev2 = gupnp_device_info_get_device (subdev1,
       "urn:schemas-upnp-org:device:WANConnectionDevice:1");
   fail_if (subdev2 == NULL, "Could not get WANConnectionDevice");
+  g_object_unref (subdev1);
 
   service = gupnp_device_info_get_service (subdev2,
       "urn:schemas-upnp-org:service:WANIPConnection:1");
   fail_if (service == NULL, "Could not get WANIPConnection");
+  g_object_unref (subdev2);
 
   g_signal_connect (service, "action-invoked::GetExternalIPAddress",
       G_CALLBACK (get_external_ip_address_cb), NULL);
@@ -195,6 +205,7 @@ run_fsupnp_test (GMainContext *mainctx, FsUpnpSimpleIgd *igd)
 
   gupnp_root_device_set_available (dev, TRUE);
 
+
   g_signal_connect (igd, "mapped-external-port",
       G_CALLBACK (mapping_external_port_cb), service);
   g_signal_connect (igd, "error-mapping-port",
diff --git a/transmitters/rawudp/fs-rawudp-component.c b/transmitters/rawudp/fs-rawudp-component.c
index a63fbf5..e5efad6 100644
--- a/transmitters/rawudp/fs-rawudp-component.c
+++ b/transmitters/rawudp/fs-rawudp-component.c
@@ -624,7 +624,10 @@ fs_rawudp_component_stop (FsRawUdpComponent *self)
 #ifdef HAVE_GUPNP
 
     if (self->priv->upnp_discovery_timeout_src)
+    {
       g_source_destroy (self->priv->upnp_discovery_timeout_src);
+      g_source_unref (self->priv->upnp_discovery_timeout_src);
+    }
     self->priv->upnp_discovery_timeout_src = NULL;
 
     if (self->priv->upnp_igd  &&
@@ -1005,7 +1008,10 @@ _upnp_mapped_external_port (FsUpnpSimpleIgdThread *igd, gchar *proto,
   }
 
   if (self->priv->upnp_discovery_timeout_src)
+  {
     g_source_destroy (self->priv->upnp_discovery_timeout_src);
+    g_source_unref (self->priv->upnp_discovery_timeout_src);
+  }
   self->priv->upnp_discovery_timeout_src = NULL;
 
   if (self->priv->local_active_candidate)
-- 
1.5.6.5




More information about the farsight-commits mailing list