GstBase/PushSrc GstBuffer ownership

Samuel Hurst samuelh at rd.bbc.co.uk
Thu Mar 26 10:49:21 PDT 2015


Hi All,

I have a query regarding how to handle buffers in a source element. I'm
using GstPushSrc at present to implement an element for GStreamer, and
I'm currently debugging a few memory leak problems that seem to be
arising from the usage of buffers, so I would like some clarification as
to their usage.

What leads me to believe the leak is thanks to my GstBuffer handling is
the output from valgrind below:

==4572== 232,616,688 bytes in 223 blocks are still reachable in loss
record 2,846 of 2,846
==4572==    at 0x4C2845D: malloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==4572==    by 0x58E770E: g_malloc (in /usr/lib64/libglib-2.0.so.0.3600.3)
==4572==    by 0x58FD7DD: g_slice_alloc (in
/usr/lib64/libglib-2.0.so.0.3600.3)
==4572==    by 0x4E600FC: _sysmem_new_block (gstallocator.c:414)
==4572==    by 0x4E6A061: gst_buffer_new_allocate (gstbuffer.c:673)
...

I'm thinking that the "still reachable" means that there's still
references being held internally because I'm not currently unreferencing
it (but feel free to correct me if this thinking is wrong!).

At present, I'm overriding the gst_base_src_create() function, which
provides a GstBuffer** object to pass data upstream. Once my element has
processed its request, it uses gst_buffer_new_allocate() to allocate a
new buffer of the appropriate size, and then I'm using gst_buffer_map to
write the data in, then _unmap()ing before returning GST_FLOW_OK.

In the documentation, it mentions that after using
gst_buffer_new_allocate() you should use gst_buffer_unref() when you're
ready to say goodbye to that buffer, but where should this be done? I'm
going to assume it's at some point after the _create() function has
returned, as otherwise the buffer will never go to the upstream
element's sink pad.


Thanks in advance,
Sam


More information about the gstreamer-devel mailing list