diff --git a/subprojects/gst-plugins-bad/ext/wpe/gstwpesrcbin.cpp b/subprojects/gst-plugins-bad/ext/wpe/gstwpesrcbin.cpp
index 5664aaa799..a47ba9c2da 100644
--- a/subprojects/gst-plugins-bad/ext/wpe/gstwpesrcbin.cpp
+++ b/subprojects/gst-plugins-bad/ext/wpe/gstwpesrcbin.cpp
@@ -449,6 +449,7 @@ gst_wpe_src_init (GstWpeSrc * src)
   GstPad *pad;
   GstPad *ghost_pad;
   GstProxyPad *proxy_pad;
+  GstPadTemplate *pad_template;
 
   gst_bin_set_suppressed_flags (GST_BIN_CAST (src),
       static_cast<GstElementFlags>(GST_ELEMENT_FLAG_SOURCE | GST_ELEMENT_FLAG_SINK));
@@ -461,9 +462,9 @@ gst_wpe_src_init (GstWpeSrc * src)
 
   gst_bin_add (GST_BIN_CAST (src), src->video_src);
 
+  pad_template = gst_static_pad_template_get (&video_src_factory);
   pad = gst_element_get_static_pad (GST_ELEMENT_CAST (src->video_src), "src");
-  ghost_pad = gst_ghost_pad_new_from_template ("video", pad,
-    gst_static_pad_template_get (&video_src_factory));
+  ghost_pad = gst_ghost_pad_new_from_template ("video", pad, pad_template);
   proxy_pad = gst_proxy_pad_get_internal (GST_PROXY_PAD (ghost_pad));
   gst_pad_set_active (GST_PAD_CAST (proxy_pad), TRUE);
 
@@ -473,6 +474,7 @@ gst_wpe_src_init (GstWpeSrc * src)
 
   gst_object_unref (proxy_pad);
   gst_object_unref (pad);
+  gst_object_unref (pad_template);
 }
 
 static gboolean
diff --git a/subprojects/gst-plugins-bad/gst/rist/gstristsink.c b/subprojects/gst-plugins-bad/gst/rist/gstristsink.c
index 484f972a6c..528a4260fe 100644
--- a/subprojects/gst-plugins-bad/gst/rist/gstristsink.c
+++ b/subprojects/gst-plugins-bad/gst/rist/gstristsink.c
@@ -558,6 +558,7 @@ gst_rist_sink_init (GstRistSink * sink)
   GstCaps *ssrc_caps;
   GstStructure *sdes = NULL;
   RistSenderBond *bond;
+  GstPadTemplate *pad_template;
 
   sink->rtpext = gst_element_factory_make ("ristrtpext", "ristrtpext");
 
@@ -616,12 +617,14 @@ gst_rist_sink_init (GstRistSink * sink)
   g_object_set (sink->ssrc_filter, "caps", ssrc_caps, NULL);
   gst_caps_unref (ssrc_caps);
 
+  pad_template = gst_static_pad_template_get (&sink_templ);
   ssrc_filter_sinkpad = gst_element_get_static_pad (sink->ssrc_filter, "sink");
   sink->sinkpad = gst_ghost_pad_new_from_template ("sink", ssrc_filter_sinkpad,
-      gst_static_pad_template_get (&sink_templ));
+      pad_template);
   gst_pad_set_event_function (sink->sinkpad, gst_rist_sink_event);
   gst_element_add_pad (GST_ELEMENT (sink), sink->sinkpad);
   gst_object_unref (ssrc_filter_sinkpad);
+  gst_object_unref (pad_template);
 
   gst_pad_add_probe (sink->sinkpad, GST_PAD_PROBE_TYPE_EVENT_UPSTREAM,
       gst_rist_sink_fix_collision, sink, NULL);
diff --git a/subprojects/gst-plugins-bad/gst/sdp/gstsdpsrc.c b/subprojects/gst-plugins-bad/gst/sdp/gstsdpsrc.c
index 184c9bfda8..6608708017 100644
--- a/subprojects/gst-plugins-bad/gst/sdp/gstsdpsrc.c
+++ b/subprojects/gst-plugins-bad/gst/sdp/gstsdpsrc.c
@@ -105,13 +105,15 @@ pad_added_cb (GstElement * element, GstPad * pad, gpointer user_data)
 {
   GstSdpSrc *self = GST_SDP_SRC_CAST (user_data);
   GstPad *ghost;
+  GstPadTemplate *pad_template;
 
+  pad_template = gst_static_pad_template_get (&src_template);
   ghost =
-      gst_ghost_pad_new_from_template (GST_PAD_NAME (pad), pad,
-      gst_static_pad_template_get (&src_template));
+      gst_ghost_pad_new_from_template (GST_PAD_NAME (pad), pad, pad_template);
   gst_pad_set_active (ghost, TRUE);
   gst_element_add_pad (GST_ELEMENT_CAST (self), ghost);
   g_object_set_data (G_OBJECT (pad), "GstSdpSrc.ghostpad", ghost);
+  gst_object_unref (pad_template);
 }
 
 static void