webrtcice: Fix memory leaks in gst_webrtc_ice_add_candidate()
authorSangchul Lee <sc11.lee@samsung.com>
Sun, 6 Feb 2022 14:20:32 +0000 (23:20 +0900)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 9 Feb 2022 09:00:25 +0000 (09:00 +0000)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1646>

subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcice.c

index 84c4e07..ada1e61 100644 (file)
@@ -639,25 +639,26 @@ gst_webrtc_ice_add_candidate (GstWebRTCICE * ice, GstWebRTCICEStream * stream,
   if (!cand) {
     /* might be a .local candidate */
     char *prefix = NULL, *address = NULL, *postfix = NULL;
-    char *new_addr, *new_candidate;
+    char *new_addr = NULL, *new_candidate = NULL;
     char *new_candv[4] = { NULL, };
+    gboolean failure = TRUE;
 
     if (!get_candidate_address (candidate, &prefix, &address, &postfix)) {
       GST_WARNING_OBJECT (ice, "Failed to retrieve address from candidate %s",
           candidate);
-      goto fail;
+      goto done;
     }
 
     if (!g_str_has_suffix (address, ".local")) {
       GST_WARNING_OBJECT (ice, "candidate address \'%s\' does not end "
           "with \'.local\'", address);
-      goto fail;
+      goto done;
     }
 
     /* FIXME: async */
     if (!(new_addr = _resolve_host (ice, address))) {
       GST_WARNING_OBJECT (ice, "Failed to resolve %s", address);
-      goto fail;
+      goto done;
     }
 
     new_candv[0] = prefix;
@@ -671,24 +672,22 @@ gst_webrtc_ice_add_candidate (GstWebRTCICE * ice, GstWebRTCICEStream * stream,
     cand =
         nice_agent_parse_remote_candidate_sdp (ice->priv->nice_agent,
         item->nice_stream_id, new_candidate);
-    g_free (new_candidate);
     if (!cand) {
       GST_WARNING_OBJECT (ice, "Could not parse candidate \'%s\'",
           new_candidate);
-      goto fail;
+      goto done;
     }
 
+    failure = FALSE;
+
+  done:
     g_free (prefix);
-    g_free (new_addr);
+    g_free (address);
     g_free (postfix);
-
-    if (0) {
-    fail:
-      g_free (prefix);
-      g_free (address);
-      g_free (postfix);
+    g_free (new_addr);
+    g_free (new_candidate);
+    if (failure)
       return;
-    }
   }
 
   if (cand->component_id == 2) {