[FFmpeg-cvslog] avutil/buffer: factor buffer_replace() out

Michael Niedermayer git at videolan.org
Fri Jan 23 04:55:40 CET 2015


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Thu Jan 15 00:40:35 2015 +0100| [b4f5da26517c101caa3a200c1cdf6553c3641f5f] | committer: Michael Niedermayer

avutil/buffer: factor buffer_replace() out

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b4f5da26517c101caa3a200c1cdf6553c3641f5f
---

 libavutil/buffer.c |   21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/libavutil/buffer.c b/libavutil/buffer.c
index c881d1a..ca102fd 100644
--- a/libavutil/buffer.c
+++ b/libavutil/buffer.c
@@ -103,14 +103,17 @@ AVBufferRef *av_buffer_ref(AVBufferRef *buf)
     return ret;
 }
 
-void av_buffer_unref(AVBufferRef **buf)
+static void buffer_replace(AVBufferRef **dst, AVBufferRef **src)
 {
     AVBuffer *b;
 
-    if (!buf || !*buf)
-        return;
-    b = (*buf)->buffer;
-    av_freep(buf);
+    b = (*dst)->buffer;
+
+    if (src) {
+        **dst = **src;
+        av_freep(src);
+    } else
+        av_freep(dst);
 
     if (!avpriv_atomic_int_add_and_fetch(&b->refcount, -1)) {
         b->free(b->opaque, b->data);
@@ -118,6 +121,14 @@ void av_buffer_unref(AVBufferRef **buf)
     }
 }
 
+void av_buffer_unref(AVBufferRef **buf)
+{
+    if (!buf || !*buf)
+        return;
+
+    buffer_replace(buf, NULL);
+}
+
 int av_buffer_is_writable(const AVBufferRef *buf)
 {
     if (buf->buffer->flags & AV_BUFFER_FLAG_READONLY)



More information about the ffmpeg-cvslog mailing list