[gst-cvs] gstreamer: buffer: avoid memory leaks

Wim Taymans wtay at kemper.freedesktop.org
Wed May 27 07:20:39 PDT 2009


Module: gstreamer
Branch: master
Commit: 791fa4381250999964482fb2c32602bfa2f0a7ab
URL:    http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=791fa4381250999964482fb2c32602bfa2f0a7ab

Author: Wim Taymans <wim.taymans at collabora.co.uk>
Date:   Wed May 27 16:17:31 2009 +0200

buffer: avoid memory leaks

Avoid leaking the caps of the dest buffer and avoid doing needless caps
refs.
When the source and target buffers are the same, return immediatly.

---

 gst/gstbuffer.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c
index d717eba..9adad9e 100644
--- a/gst/gstbuffer.c
+++ b/gst/gstbuffer.c
@@ -193,6 +193,10 @@ gst_buffer_copy_metadata (GstBuffer * dest, const GstBuffer * src,
   g_return_if_fail (dest != NULL);
   g_return_if_fail (src != NULL);
 
+  /* nothing to copy if the buffers are the same */
+  if (G_UNLIKELY (dest == src))
+    return;
+
   GST_CAT_LOG (GST_CAT_BUFFER, "copy %p to %p", src, dest);
 
   if (flags & GST_BUFFER_COPY_FLAGS) {
@@ -214,10 +218,7 @@ gst_buffer_copy_metadata (GstBuffer * dest, const GstBuffer * src,
   }
 
   if (flags & GST_BUFFER_COPY_CAPS) {
-    if (GST_BUFFER_CAPS (src))
-      GST_BUFFER_CAPS (dest) = gst_caps_ref (GST_BUFFER_CAPS (src));
-    else
-      GST_BUFFER_CAPS (dest) = NULL;
+    gst_caps_replace (&GST_BUFFER_CAPS (dest), GST_BUFFER_CAPS (src));
   }
 }
 





More information about the Gstreamer-commits mailing list