[gst-devel] Failed to free the memory allocated by gst_pad_alloc_buffer_and_set_caps()
Hu, Gang A
gang.a.hu at intel.com
Fri Aug 6 12:10:49 CEST 2010
I guess I found the reason after read my code and the patch for v4l2src.
The error happened because the GST_BUFFER_DATA of the buffer from pad_alloc() are freed two times.
When I allocated the buffer with gst_pad_alloc_buffer_and_set_caps(..., &buffer1).
I assigned the GST_BUFFER_DATA to another GstBuffer "buffer2". GST_BUFFER_DATA (buffer2) =buffer1->data;
Buffer2 is freed in some place and I guess the GST_BUFFER_DATA is freed also.
So when buffer1 is unreffed, the double free error happened for buffer1->data.
I use USERPTR to do the buffer sharing with the downstream element.
BTW, Edward's guess is right.
* OR you are doing a free on the GST_BUFFER_DATA field of the buffer
that downstream returned (you shouldn't do that, that memory location is
handled by GstBuffer).
From: Arnout Vandecappelle [mailto:arnout at mind.be]
Sent: Friday, August 06, 2010 12:35 AM
To: gstreamer-devel at lists.sourceforge.net
Cc: Hu, Gang A
Subject: Re: [gst-devel] Failed to free the memory allocated by gst_pad_alloc_buffer_and_set_caps()
I seem to remember I posted patches for v4l2src to support
V4L2_MEMORY_USERPTR. You could look at these to see how to handle the
situation. Check out https://bugzilla.gnome.org/show_bug.cgi?id=583890
In the pipeline you gave, the buffer will be allocated by the
ffmpegcolorspace element, I believe. Look at the pad_alloc function of the
ffmpegcolorspace sink pad to find out. (Default is to allocate using
Why do you want a USERPTR anyway?
On Wednesday 04 August 2010 14:33:02, Hu, Gang A wrote:
> I had a v4l2 camera driver with the "V4L2_MEMORY_USERPTR" type memory
> support and a camera source element "v4l2newcamsrc" to support this type
> memory. When I running the pipeline bellow
> "gst-launch v4l2newcamsrc num-buffers=1 ! ffmpegcolorspace !
> video/x-raw-yuv,width=640,height=480 ! filesink location=image_640.yuv"
> The image can be captured successfully.
> But when the buffers are freed in the camera source element, there will
> always be an error message in the terminal.
> *** glibc detected *** /usr/local/meego/bin/gst-launch-0.10: free():
> invalid pointer: 0xb73c8008 *** ======= Backtrace: =========
> xb77b94df] .
> I use gst_pad_alloc_buffer_and_set_caps() to allocate the buffer from the
> download element in the camera source element. When the application
> exit, gst_buffer_unref (buffer) will be called to free the memory. This
> code case the error above after debugging with GDB.
> I have two questions about that.
> 1. Which element is responsible for the memory allocation when call
> "gst_pad_alloc_buffer_and_set_caps()" in camera source element in my
> pipeline. 2. How to free the memory allocated by
> "gst_pad_alloc_buffer_and_set_caps()"? Why the error "free(): invalid
> pointer: 0xb73c8008 ***" occurred.
> Best Regards!
> Hu Gang
Arnout Vandecappelle arnout at mind be
Senior Embedded Software Architect +32-16-286540
G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint: 31BB CF53 8660 6F88 345D 54CC A836 5879 20D7 CF43
More information about the gstreamer-devel