After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 407793 - memory leaks of sdpmessage.c
memory leaks of sdpmessage.c
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
0.10.5
Other Linux
: Normal normal
: 0.10.6
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2007-02-14 09:04 UTC by jp.liu
Modified: 2007-02-14 15:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
sdpmessage.patch (3.97 KB, patch)
2007-02-14 09:05 UTC, jp.liu
none Details | Review

Description jp.liu 2007-02-14 09:04:22 UTC
There are some memory leaks of sdpmessage in sdpmessage.c when sdp_message_clean.
The following patch fix it.


--- sdpmessage.c.orig	2006-09-21 00:06:28.000000000 +0800
+++ sdpmessage.c	2007-02-14 09:59:02.858530144 +0800
@@ -48,7 +48,7 @@
 /* FIXME, is currently allocated on the stack */
 #define MAX_LINE_LEN	1024 * 16
 
-#define FREE_STRING(field)      g_free ((field)); (field) = NULL;
+#define FREE_STRING(field)      if(field) { g_free ((field)); (field) = NULL; }
 #define FREE_ARRAY(field)       \
 G_STMT_START {                  \
   if (field)                    \
@@ -147,16 +147,77 @@
 RTSPResult
 sdp_message_clean (SDPMessage * msg)
 {
+  unsigned int i;
+
   g_return_val_if_fail (msg != NULL, RTSP_EINVAL);
 
+  for(i=0; i<msg->emails->len; i++)
+  {
+      g_free (g_array_index(msg->emails, gchar *, i));
+  }
   FREE_ARRAY (msg->emails);
+
+  for(i=0; i<msg->phones->len; i++)
+  {
+      g_free (g_array_index(msg->phones, gchar *, i));
+  }
   FREE_ARRAY (msg->phones);
+
+  for(i=0; i<msg->bandwidths->len; i++)
+  {
+      SDPBandwidth* bw = &g_array_index(msg->bandwidths, SDPBandwidth, i);
+      FREE_STRING (bw->bwtype);
+  }
   FREE_ARRAY (msg->bandwidths);
+
+  for(i=0; i<msg->times->len; i++)
+  {
+      SDPTime* time = &g_array_index(msg->times, SDPTime, i);
+      FREE_STRING (time->start);
+      FREE_STRING (time->stop);
+  }
   FREE_ARRAY (msg->times);
+
+  for(i=0; i<msg->zones->len; i++)
+  {
+      SDPZone* zone = &g_array_index(msg->zones, SDPZone, i);
+      FREE_STRING (zone->time);
+      FREE_STRING (zone->typed_time);
+  }
   FREE_ARRAY (msg->zones);
+
+  for(i=0; i<msg->attributes->len; i++)
+  {
+      SDPAttribute* attr = &g_array_index(msg->attributes, SDPAttribute, i);
+      FREE_STRING (attr->key);
+      FREE_STRING (attr->value);
+  }
   FREE_ARRAY (msg->attributes);
+
+  for(i=0; i<msg->medias->len; i++)
+  {
+      SDPMedia* media = &g_array_index(msg->medias, SDPMedia, i);
+      sdp_media_clean(media);
+  }
   FREE_ARRAY (msg->medias);
 
+  //added FREE_STRING by jp.liu
+  FREE_STRING (msg->version);
+  FREE_STRING (msg->origin.username);
+  FREE_STRING (msg->origin.sess_id);
+  FREE_STRING (msg->origin.sess_version);
+  FREE_STRING (msg->origin.nettype);
+  FREE_STRING (msg->origin.addrtype);
+  FREE_STRING (msg->origin.addr);
+  FREE_STRING (msg->session_name);
+  FREE_STRING (msg->information);
+  FREE_STRING (msg->uri);
+  FREE_STRING (msg->connection.nettype);
+  FREE_STRING (msg->connection.addrtype);
+  FREE_STRING (msg->connection.address);
+  FREE_STRING (msg->key.type);
+  FREE_STRING (msg->key.data);
+
   return RTSP_OK;
 }
 
@@ -187,6 +248,65 @@
   return sdp_media_init (newmedia);
 }
 
+//added these 2 functions by jp.liu
+
+RTSPResult
+sdp_media_clean(SDPMedia *media)
+{
+    unsigned int i;
+
+    FREE_STRING (media->media);
+    FREE_STRING (media->proto);
+    FREE_STRING (media->information);
+    FREE_STRING (media->key.data);
+    FREE_STRING (media->key.type);
+
+    for(i=0; i<media->fmts->len; i++)
+    {
+        char* fmt = g_array_index(media->fmts, gchar *, i);
+        FREE_STRING (fmt);
+    }
+    FREE_ARRAY (media->fmts);
+
+    for(i=0; i<media->connections->len; i++)
+    {
+        SDPConnection* conn = &g_array_index(media->connections, SDPConnection, i);
+        FREE_STRING (conn->nettype);
+        FREE_STRING (conn->addrtype);
+        FREE_STRING (conn->address);
+    }
+    FREE_ARRAY (media->connections);
+
+    for(i=0; i<media->bandwidths->len; i++)
+    {
+        SDPBandwidth* bw = &g_array_index(media->bandwidths, SDPBandwidth, i);
+        FREE_STRING (bw->bwtype);
+    }
+    FREE_ARRAY (media->bandwidths);
+
+    for(i=0; i<media->attributes->len; i++)
+    {
+        SDPAttribute* attr = &g_array_index(media->attributes, SDPAttribute, i);
+        FREE_STRING (attr->key);
+        FREE_STRING (attr->value);
+    }
+    FREE_ARRAY (media->attributes);
+
+    return RTSP_OK;
+}
+
+RTSPResult
+sdp_media_free(SDPMedia *media)
+{
+    g_return_val_if_fail (media != NULL, RTSP_EINVAL);
+
+    sdp_media_clean(media);
+
+    g_free(media);
+
+    return RTSP_OK;
+}
+
 RTSPResult
 sdp_media_init (SDPMedia * media)
 {
Comment 1 jp.liu 2007-02-14 09:05:43 UTC
Created attachment 82521 [details] [review]
sdpmessage.patch

This patch fix sdpmessage's memory leaks.
Comment 2 Wim Taymans 2007-02-14 15:25:03 UTC
        * gst/rtsp/sdpmessage.c: (sdp_origin_init), (sdp_connection_init),
        (sdp_bandwidth_init), (sdp_time_init), (sdp_zone_init),
        (sdp_key_init), (sdp_attribute_init), (sdp_message_init),
        (sdp_message_uninit), (sdp_message_free), (sdp_media_init),
        (sdp_media_uninit), (sdp_media_free), (sdp_message_add_media),
        (sdp_parse_line):
        * gst/rtsp/sdpmessage.h:
        Based on patch by: jp.liu <jp_liu at astrocom dot cn>
        Fix memory management of SDP messages. Fixes #407793.