[GStreamer] clean-up various leaks
authorphiln@webkit.org <philn@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Feb 2016 10:30:08 +0000 (10:30 +0000)
committerphiln@webkit.org <philn@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Feb 2016 10:30:08 +0000 (10:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=154285

Reviewed by Carlos Garcia Campos.

* platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp:
(webkit_web_audio_src_init): Take full ownership of the GstTask.
* platform/graphics/gstreamer/GRefPtrGStreamer.cpp:
(WTF::adoptGRef): Null pointer support in ASSERTs.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::initializeGStreamerAndRegisterWebKitElements): Take full ownership of the GstElementFactory pointers.
(WebCore::MediaPlayerPrivateGStreamer::isAvailable): Ditto.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp
Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.cpp
Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp

index 2225289..060e481 100644 (file)
@@ -1,3 +1,18 @@
+2016-02-19  Philippe Normand  <pnormand@igalia.com>
+
+        [GStreamer] clean-up various leaks
+        https://bugs.webkit.org/show_bug.cgi?id=154285
+
+        Reviewed by Carlos Garcia Campos.
+
+        * platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp:
+        (webkit_web_audio_src_init): Take full ownership of the GstTask.
+        * platform/graphics/gstreamer/GRefPtrGStreamer.cpp:
+        (WTF::adoptGRef): Null pointer support in ASSERTs.
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+        (WebCore::initializeGStreamerAndRegisterWebKitElements): Take full ownership of the GstElementFactory pointers.
+        (WebCore::MediaPlayerPrivateGStreamer::isAvailable): Ditto.
+
 2016-02-18  Andy Estes  <aestes@apple.com>
 
         Revert to dispatching the popstate event synchronously
index 4d92c11..13f6e8d 100644 (file)
@@ -193,7 +193,7 @@ static void webkit_web_audio_src_init(WebKitWebAudioSrc* src)
     priv->bus = 0;
 
     g_rec_mutex_init(&priv->mutex);
-    priv->task = gst_task_new(reinterpret_cast<GstTaskFunction>(webKitWebAudioSrcLoop), src, 0);
+    priv->task = adoptGRef(gst_task_new(reinterpret_cast<GstTaskFunction>(webKitWebAudioSrcLoop), src, 0));
 
     gst_task_set_lock(priv->task.get(), &priv->mutex);
 }
index e642947..47113f6 100644 (file)
@@ -27,7 +27,7 @@ namespace WTF {
 
 template <> GRefPtr<GstElement> adoptGRef(GstElement* ptr)
 {
-    ASSERT(!ptr || !g_object_is_floating(G_OBJECT(ptr)));
+    ASSERT(!ptr || !g_object_is_floating(ptr));
     return GRefPtr<GstElement>(ptr, GRefPtrAdopt);
 }
 
@@ -47,7 +47,7 @@ template <> void derefGPtr<GstElement>(GstElement* ptr)
 
 template <> GRefPtr<GstPad> adoptGRef(GstPad* ptr)
 {
-    ASSERT(!ptr || !g_object_is_floating(G_OBJECT(ptr)));
+    ASSERT(!ptr || !g_object_is_floating(ptr));
     return GRefPtr<GstPad>(ptr, GRefPtrAdopt);
 }
 
@@ -67,7 +67,7 @@ template <> void derefGPtr<GstPad>(GstPad* ptr)
 
 template <> GRefPtr<GstPadTemplate> adoptGRef(GstPadTemplate* ptr)
 {
-    ASSERT(!ptr || !g_object_is_floating(G_OBJECT(ptr)));
+    ASSERT(!ptr || !g_object_is_floating(ptr));
     return GRefPtr<GstPadTemplate>(ptr, GRefPtrAdopt);
 }
 
@@ -105,7 +105,7 @@ template <> void derefGPtr<GstCaps>(GstCaps* ptr)
 
 template <> GRefPtr<GstContext> adoptGRef(GstContext* ptr)
 {
-    ASSERT(!g_object_is_floating(G_OBJECT(ptr)));
+    ASSERT(!g_object_is_floating(ptr));
     return GRefPtr<GstContext>(ptr, GRefPtrAdopt);
 }
 
@@ -124,7 +124,8 @@ template <> void derefGPtr<GstContext>(GstContext* ptr)
 
 template <> GRefPtr<GstTask> adoptGRef(GstTask* ptr)
 {
-    ASSERT(!g_object_is_floating(G_OBJECT(ptr)));
+    // There is no need to check the object reference is floating here because
+    // gst_task_init() always sinks it.
     return GRefPtr<GstTask>(ptr, GRefPtrAdopt);
 }
 
@@ -144,7 +145,7 @@ template <> void derefGPtr<GstTask>(GstTask* ptr)
 
 template <> GRefPtr<GstBus> adoptGRef(GstBus* ptr)
 {
-    ASSERT(!g_object_is_floating(G_OBJECT(ptr)));
+    ASSERT(!ptr || !g_object_is_floating(ptr));
     return GRefPtr<GstBus>(ptr, GRefPtrAdopt);
 }
 
@@ -164,7 +165,7 @@ template <> void derefGPtr<GstBus>(GstBus* ptr)
 
 template <> GRefPtr<GstElementFactory> adoptGRef(GstElementFactory* ptr)
 {
-    ASSERT(!g_object_is_floating(G_OBJECT(ptr)));
+    ASSERT(!ptr || !g_object_is_floating(ptr));
     return GRefPtr<GstElementFactory>(ptr, GRefPtrAdopt);
 }
 
@@ -317,7 +318,7 @@ template<> void derefGPtr<GstMessage>(GstMessage* ptr)
 
 template <> GRefPtr<WebKitVideoSink> adoptGRef(WebKitVideoSink* ptr)
 {
-    ASSERT(!ptr || !g_object_is_floating(G_OBJECT(ptr)));
+    ASSERT(!ptr || !g_object_is_floating(ptr));
     return GRefPtr<WebKitVideoSink>(ptr, GRefPtrAdopt);
 }
 
@@ -337,7 +338,7 @@ template <> void derefGPtr<WebKitVideoSink>(WebKitVideoSink* ptr)
 
 template <> GRefPtr<WebKitWebSrc> adoptGRef(WebKitWebSrc* ptr)
 {
-    ASSERT(!ptr || !g_object_is_floating(G_OBJECT(ptr)));
+    ASSERT(!ptr || !g_object_is_floating(ptr));
     return GRefPtr<WebKitWebSrc>(ptr, GRefPtrAdopt);
 }
 
index 8a33a6c..75bb533 100644 (file)
@@ -107,14 +107,14 @@ bool initializeGStreamerAndRegisterWebKitElements()
     if (!initializeGStreamer())
         return false;
 
-    GRefPtr<GstElementFactory> srcFactory = gst_element_factory_find("webkitwebsrc");
+    GRefPtr<GstElementFactory> srcFactory = adoptGRef(gst_element_factory_find("webkitwebsrc"));
     if (!srcFactory) {
         GST_DEBUG_CATEGORY_INIT(webkit_media_player_debug, "webkitmediaplayer", 0, "WebKit media player");
         gst_element_register(0, "webkitwebsrc", GST_RANK_PRIMARY + 100, WEBKIT_TYPE_WEB_SRC);
     }
 
 #if ENABLE(MEDIA_SOURCE)
-    GRefPtr<GstElementFactory> WebKitMediaSrcFactory = gst_element_factory_find("webkitmediasrc");
+    GRefPtr<GstElementFactory> WebKitMediaSrcFactory = adoptGRef(gst_element_factory_find("webkitmediasrc"));
     if (!WebKitMediaSrcFactory)
         gst_element_register(0, "webkitmediasrc", GST_RANK_PRIMARY + 100, WEBKIT_TYPE_MEDIA_SRC);
 #endif
@@ -126,7 +126,7 @@ bool MediaPlayerPrivateGStreamer::isAvailable()
     if (!initializeGStreamerAndRegisterWebKitElements())
         return false;
 
-    GRefPtr<GstElementFactory> factory = gst_element_factory_find("playbin");
+    GRefPtr<GstElementFactory> factory = adoptGRef(gst_element_factory_find("playbin"));
     return factory;
 }