From 5cedf017f50f43f1eca7108ff4a9c09daba2c3e2 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Wed, 19 Jan 2022 23:17:23 +0900 Subject: [PATCH] webrtc: Fix memory leaks Redundant condition and unreachable codes are also removed. Part-of: --- subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c | 11 ++++------- subprojects/gst-plugins-bad/ext/webrtc/webrtcdatachannel.c | 3 ++- subprojects/gst-plugins-bad/ext/webrtc/webrtcsdp.c | 1 + 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c b/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c index db1188a..fbbba46 100644 --- a/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c +++ b/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c @@ -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; } diff --git a/subprojects/gst-plugins-bad/ext/webrtc/webrtcdatachannel.c b/subprojects/gst-plugins-bad/ext/webrtc/webrtcdatachannel.c index 9ad73c9..e0fef6d 100644 --- a/subprojects/gst-plugins-bad/ext/webrtc/webrtcdatachannel.c +++ b/subprojects/gst-plugins-bad/ext/webrtc/webrtcdatachannel.c @@ -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); diff --git a/subprojects/gst-plugins-bad/ext/webrtc/webrtcsdp.c b/subprojects/gst-plugins-bad/ext/webrtc/webrtcsdp.c index 2f8dcf6..4c033b4 100644 --- a/subprojects/gst-plugins-bad/ext/webrtc/webrtcsdp.c +++ b/subprojects/gst-plugins-bad/ext/webrtc/webrtcsdp.c @@ -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; } } -- 2.7.4