[gst-cvs] gstreamer: adapter: don't use realloc, it does a memcpy

Wim Taymans wtay at kemper.freedesktop.org
Wed May 13 14:55:19 PDT 2009


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

Author: Wim Taymans <wim.taymans at collabora.co.uk>
Date:   Wed May 13 23:52:02 2009 +0200

adapter: don't use realloc, it does a memcpy

Don't use realloc to grow the scratch area because we don't want the memcpy the
old useless data into the new area before we write our new stuff in it.

---

 libs/gst/base/gstadapter.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libs/gst/base/gstadapter.c b/libs/gst/base/gstadapter.c
index 9143301..0acfd38 100644
--- a/libs/gst/base/gstadapter.c
+++ b/libs/gst/base/gstadapter.c
@@ -402,8 +402,10 @@ gst_adapter_peek (GstAdapter * adapter, guint size)
     adapter->assembled_size = (size / DEFAULT_SIZE + 1) * DEFAULT_SIZE;
     GST_DEBUG_OBJECT (adapter, "resizing internal buffer to %u",
         adapter->assembled_size);
-    adapter->assembled_data =
-        g_realloc (adapter->assembled_data, adapter->assembled_size);
+    /* no g_realloc to avoid a memcpy that is not desired here since we are
+     * going to copy new data into the area below */
+    g_free (adapter->assembled_data);
+    adapter->assembled_data = g_malloc (adapter->assembled_size);
   }
   adapter->assembled_len = size;
 





More information about the Gstreamer-commits mailing list