memory leak on custom meta data insert

Michael Gruner michael.gruner at ridgerun.com
Mon Mar 7 17:04:02 UTC 2022


Hey Tom

Is this line ok?

  *outbuf = gst_buffer_make_writable(input);

Shouldn’t it be:

  *outbuf = gst_buffer_make_writable(*outbuf);

The way it is right now you are leaking the outbuf creating when calling:

 ret = GST_BASE_TRANSFORM_CLASS(gst_mtdata_meta_inject_parent_class)->prepare_output_buffer(trans, input, outbuf);

Michael 

> On 6 Mar 2022, at 21:11, tom via gstreamer-devel <gstreamer-devel at lists.freedesktop.org> wrote:
> 
> Hello,
> 
> I'm trying to write a simple plugin that only inserts data as meta data to the stream.
> My plugin is derived from GstBaseTransform
> 
> typedef struct GstMtdataMetaInject
> {
>   GstBaseTransform base_mtdataplugins;
> 
> and i've created a simple meta data like: (see attached files)
> 
> struct _MtdataMeta
> {
>     GstMeta meta;
>     gchar *jsonstring;
> };
> 
> 
> and to insert the meta data (on every frame for now)
> 
> 
> static GstFlowReturn
> gst_mtdata_meta_inject_prepare_output_buffer(GstBaseTransform *trans, GstBuffer *input, GstBuffer **outbuf)
> {
>   GstMtdataMetaInject *self = GST_MTDMETAINJECT(trans);
>   GstFlowReturn ret;
>   ret = GST_BASE_TRANSFORM_CLASS(gst_mtdata_meta_inject_parent_class)->prepare_output_buffer(trans, input, outbuf);
>   if (ret != GST_FLOW_OK)
>     return ret;
>   *outbuf = gst_buffer_make_writable(input);
>   if (*outbuf != NULL)
>   {
>     // string hello = StringUtils::current_date_time_string();
>     // string hello = "12345678901234";
>     string hello = StringUtils::random_string(14);
> 
>     MtdataMeta *in = gst_buffer_add_mtdata_meta(*outbuf, (gchar *)hello.c_str());
> 
>     GST_WARNING("Added metdata: %s", in->jsonstring);
>   }
>   return ret;
> }
> however i'm getting a quite fast memory leak that i can see in gst-launch-1.0 where it goes from 30% memory up to 60% in a matter of a minute.
> the funny think is that if i change the meta data string to be something constant like "12345678901234" with the same length, there is no memory leak and it stays on 28% forever.
> 
> Do I need to go to the last element in the stream and 'free' the meta data so it doesn't add up ?
> Kind regards,
> Tom
> 
> <mtdata_meta.h><mtdata_meta.cpp><gstmtdmetainject.h><gstmtdmetainject.cpp>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20220307/4c70fead/attachment.htm>


More information about the gstreamer-devel mailing list