[gst-devel] Memory leak on a PushSrc subclass

Jan Schmidt thaytan at noraisin.net
Wed Aug 16 11:17:49 CEST 2006


On Wed, 2006-08-16 at 10:26 +0200, Corentin BARON wrote:
> Hello list,
> 
> I've got a memory leak problem I couldn't deal with. In my create()  
> function, I instanciate a GstBuffer, and the data I put in it, and  
> then set the GstBuffer's data pointer to the data I just created.  
> Everything works fine excepts that the data I created seems to be  
> lost somewhere in the pipeline.
> 
> Here's a part of the create() function:
> 
> > static GstFlowReturn gst_blinkysrc_create(GstPushSrc * psrc,  
> > GstBuffer ** buffer)
> > {
> > 	GstBuffer *buf;
> > 	void *dest;
> > 	GstBlinkySrc *filter = GST_BLINKYSRC(psrc);
> > 	[...]
> > 	buf = gst_buffer_new();
...
> > 	gst_buffer_set_data(buf, dest, outbufsize);
> > 	g_return_val_if_fail(buf != NULL, GST_FLOW_ERROR);
> > 	*buffer = buf;
> > 	return GST_FLOW_OK;
> > }

When you do gst_buffer_new() and then set the data, the buffer considers
that it doesn't own the data itself and won't free it. You can either do
gst_buffer_new_and_alloc(), or ensure that when you set the data on the
buffer you also set the malloc_data member of the GstBuffer to point to
the array.

>From the DevHelp docs for GstBuffer:

guint8 *malloc_data;  a pointer to the allocated memory associated with
this buffer. When the buffer is freed, this data will freed with free().

Regards,
Jan.

-- 
Jan Schmidt thaytan at noraisin.net

Have you been half-asleep? Have you heard voices?
I've heard them calling my name...
-Kermit the Frog (Rainbow Connection)






More information about the gstreamer-devel mailing list