From 791fa4381250999964482fb2c32602bfa2f0a7ab Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 27 May 2009 16:17:31 +0200 Subject: [PATCH] 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 file 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)); } } -- 2.7.4