[GStreamer] More leaks in TextCombinerGStreamer
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Dec 2017 08:52:21 +0000 (08:52 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Dec 2017 08:52:21 +0000 (08:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180331

Reviewed by Michael Catanzaro.

I've noticed more leaks reading the code, but I couldn't check them with valgrind, because I don't know how to
trigger that code path. This patch cleans up the file using smart pointer everywhere.

* platform/graphics/gstreamer/TextCombinerGStreamer.cpp:
(webkit_text_combiner_pad_init):
(webkitTextCombinerPadEvent):
(webkitTextCombinerReleasePad):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225473 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/gstreamer/TextCombinerGStreamer.cpp

index 1d6cedc..7866628 100644 (file)
@@ -1,3 +1,18 @@
+2017-12-04  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GStreamer] More leaks in TextCombinerGStreamer
+        https://bugs.webkit.org/show_bug.cgi?id=180331
+
+        Reviewed by Michael Catanzaro.
+
+        I've noticed more leaks reading the code, but I couldn't check them with valgrind, because I don't know how to
+        trigger that code path. This patch cleans up the file using smart pointer everywhere.
+
+        * platform/graphics/gstreamer/TextCombinerGStreamer.cpp:
+        (webkit_text_combiner_pad_init):
+        (webkitTextCombinerPadEvent):
+        (webkitTextCombinerReleasePad):
+
 2017-12-04  Jer Noble  <jer.noble@apple.com>
 
         Include 'video/*' in image request Accept header if browser supports video media in image contexts.
index 4d33329..9219e31 100644 (file)
@@ -94,8 +94,6 @@ static void webkit_text_combiner_init(WebKitTextCombiner* combiner)
 
 static void webkit_text_combiner_pad_init(WebKitTextCombinerPad* pad)
 {
-    pad->tags = 0;
-
     gst_pad_set_event_function(GST_PAD(pad), webkitTextCombinerPadEvent);
 }
 
@@ -137,17 +135,17 @@ static gboolean webkitTextCombinerPadEvent(GstPad* pad, GstObject* parent, GstEv
         gst_event_parse_caps(event, &caps);
         ASSERT(caps);
 
-        GstPad* target = gst_ghost_pad_get_target(GST_GHOST_PAD(pad));
+        GRefPtr<GstPad> target = adoptGRef(gst_ghost_pad_get_target(GST_GHOST_PAD(pad)));
         ASSERT(target);
 
-        GstElement* targetParent = gst_pad_get_parent_element(target);
+        GRefPtr<GstElement> targetParent = adoptGRef(gst_pad_get_parent_element(target.get()));
         ASSERT(targetParent);
 
-        GstCaps* textCaps = gst_caps_new_empty_simple("text/x-raw");
-        if (gst_caps_can_intersect(textCaps, caps)) {
+        GRefPtr<GstCaps> textCaps = adoptGRef(gst_caps_new_empty_simple("text/x-raw"));
+        if (gst_caps_can_intersect(textCaps.get(), caps)) {
             /* Caps are plain text, put a WebVTT encoder between the ghostpad and
              * the funnel */
-            if (targetParent == combiner->funnel) {
+            if (targetParent.get() == combiner->funnel) {
                 /* Setup a WebVTT encoder */
                 GstElement* encoder = gst_element_factory_make("webvttenc", nullptr);
                 ASSERT(encoder);
@@ -159,45 +157,38 @@ static gboolean webkitTextCombinerPadEvent(GstPad* pad, GstObject* parent, GstEv
                 ASSERT(ret);
 
                 /* Switch the ghostpad to target the WebVTT encoder */
-                GstPad* sinkPad = gst_element_get_static_pad(encoder, "sink");
+                GRefPtr<GstPad> sinkPad = adoptGRef(gst_element_get_static_pad(encoder, "sink"));
                 ASSERT(sinkPad);
 
-                ret = gst_ghost_pad_set_target(GST_GHOST_PAD(pad), sinkPad);
+                ret = gst_ghost_pad_set_target(GST_GHOST_PAD(pad), sinkPad.get());
                 ASSERT(ret);
-                gst_object_unref(sinkPad);
 
                 /* Connect the WebVTT encoder to the funnel */
-                GstPad* srcPad = gst_element_get_static_pad(encoder, "src");
+                GRefPtr<GstPad> srcPad = adoptGRef(gst_element_get_static_pad(encoder, "src"));
                 ASSERT(srcPad);
 
-                ret = GST_PAD_LINK_SUCCESSFUL(gst_pad_link(srcPad, target));
+                ret = GST_PAD_LINK_SUCCESSFUL(gst_pad_link(srcPad.get(), target.get()));
                 ASSERT(ret);
-                gst_object_unref(srcPad);
             } /* else: pipeline is already correct */
         } else {
             /* Caps are not plain text, remove the WebVTT encoder */
-            if (targetParent != combiner->funnel) {
+            if (targetParent.get() != combiner->funnel) {
                 /* Get the funnel sink pad */
-                GstPad* srcPad = gst_element_get_static_pad(targetParent, "src");
+                GRefPtr<GstPad> srcPad = adoptGRef(gst_element_get_static_pad(targetParent.get(), "src"));
                 ASSERT(srcPad);
 
-                GstPad* sinkPad = gst_pad_get_peer(srcPad);
+                GRefPtr<GstPad> sinkPad = adoptGRef(gst_pad_get_peer(srcPad.get()));
                 ASSERT(sinkPad);
-                gst_object_unref(srcPad);
 
                 /* Switch the ghostpad to target the funnel */
-                ret = gst_ghost_pad_set_target(GST_GHOST_PAD(pad), sinkPad);
+                ret = gst_ghost_pad_set_target(GST_GHOST_PAD(pad), sinkPad.get());
                 ASSERT(ret);
-                gst_object_unref(sinkPad);
 
                 /* Remove the WebVTT encoder */
-                ret = gst_bin_remove(GST_BIN(combiner), targetParent);
+                ret = gst_bin_remove(GST_BIN(combiner), targetParent.get());
                 ASSERT(ret);
             } /* else: pipeline is already correct */
         }
-        gst_caps_unref(textCaps);
-        gst_object_unref(targetParent);
-        gst_object_unref(target);
         break;
     }
     case GST_EVENT_TAG: {
@@ -254,13 +245,12 @@ static GstPad* webkitTextCombinerRequestNewPad(GstElement * element,
 static void webkitTextCombinerReleasePad(GstElement *element, GstPad *pad)
 {
     WebKitTextCombiner* combiner = WEBKIT_TEXT_COMBINER(element);
-    GstPad* peer = gst_pad_get_peer(pad);
-    if (peer) {
-        GstElement* parent = gst_pad_get_parent_element(peer);
+    if (GRefPtr<GstPad> peer = adoptGRef(gst_pad_get_peer(pad))) {
+        GRefPtr<GstElement> parent = adoptGRef(gst_pad_get_parent_element(peer.get()));
         ASSERT(parent);
-        gst_element_release_request_pad(parent, peer);
-        if (parent != combiner->funnel)
-            gst_bin_remove(GST_BIN(combiner), parent);
+        gst_element_release_request_pad(parent.get(), peer.get());
+        if (parent.get() != combiner->funnel)
+            gst_bin_remove(GST_BIN(combiner), parent.get());
     }
 
     gst_element_remove_pad(element, pad);