webrtc: Fix memory leaks
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 19 Jan 2022 14:17:23 +0000 (23:17 +0900)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Sat, 22 Jan 2022 11:21:18 +0000 (11:21 +0000)
Redundant condition and unreachable codes are also removed.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1544>

subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c
subprojects/gst-plugins-bad/ext/webrtc/webrtcdatachannel.c
subprojects/gst-plugins-bad/ext/webrtc/webrtcsdp.c

index db1188a..fbbba46 100644 (file)
@@ -3352,7 +3352,7 @@ _create_offer_task (GstWebRTCBin * webrtc, const GstStructure * options,
 
     reserved_pts = gather_reserved_pts (webrtc);
     if (last_offer && _parse_bundle (last_offer, &last_bundle, NULL)
-        && last_bundle && last_bundle && last_bundle[0]
+        && last_bundle && last_bundle[0]
         && _get_bundle_index (last_offer, last_bundle, &bundle_media_index)) {
       bundle_ufrag =
           g_strdup (_media_get_ice_ufrag (last_offer, bundle_media_index));
@@ -4746,6 +4746,7 @@ _set_rtx_ptmap_from_stream (GstWebRTCBin * webrtc, TransportStream * stream)
       g_object_set (stream->rtxsend, "payload-type-map", pt_map, NULL);
 
     gst_structure_free (pt_map);
+    g_free (rtx_pt);
   }
 }
 
@@ -6482,7 +6483,6 @@ on_rtpbin_request_aux_sender (GstElement * rtpbin, guint session_id,
 {
   TransportStream *stream;
   gboolean have_rtx = FALSE;
-  GstStructure *pt_map = NULL;
   GstElement *ret = NULL;
 
   stream = _find_transport_for_session (webrtc, session_id);
@@ -6490,8 +6490,8 @@ on_rtpbin_request_aux_sender (GstElement * rtpbin, guint session_id,
   if (stream)
     have_rtx = transport_stream_get_pt (stream, "RTX", -1) != 0;
 
-  GST_LOG_OBJECT (webrtc, "requesting aux sender for stream %" GST_PTR_FORMAT
-      " with pt map %" GST_PTR_FORMAT, stream, pt_map);
+  GST_LOG_OBJECT (webrtc, "requesting aux sender for stream %" GST_PTR_FORMAT,
+      stream);
 
   if (have_rtx) {
     GstElement *rtx;
@@ -6543,9 +6543,6 @@ on_rtpbin_request_aux_sender (GstElement * rtpbin, guint session_id,
   }
 
 out:
-  if (pt_map)
-    gst_structure_free (pt_map);
-
   return ret;
 }
 
index 9ad73c9..e0fef6d 100644 (file)
@@ -822,7 +822,7 @@ webrtc_data_channel_send_string (GstWebRTCDataChannel * base_channel,
     ppid = DATA_CHANNEL_PPID_WEBRTC_STRING_EMPTY;
   } else {
     gsize size = strlen (str);
-    gchar *str_copy = g_strdup (str);
+    gchar *str_copy;
 
     if (!_is_within_max_message_size (channel, size)) {
       GError *error = NULL;
@@ -835,6 +835,7 @@ webrtc_data_channel_send_string (GstWebRTCDataChannel * base_channel,
       return;
     }
 
+    str_copy = g_strdup (str);
     buffer =
         gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, str_copy,
         size, 0, size, str_copy, g_free);
index 2f8dcf6..4c033b4 100644 (file)
@@ -569,6 +569,7 @@ _media_replace_setup (GstSDPMedia * media, GstWebRTCDTLSSetup setup)
       GST_TRACE ("replace setup:%s with setup:%s", attr->value, setup_str);
       gst_sdp_attribute_set (&new_attr, "setup", setup_str);
       gst_sdp_media_replace_attribute (media, i, &new_attr);
+      g_free (setup_str);
       return;
     }
   }