GNOME Bugzilla – Bug 554545
gst.Pad methods that return a new buffer as function argument leaks it
Last modified: 2008-12-06 15:52:46 UTC
Please describe the problem: It looks like when using a python element driving the pipeline in pull-mode the call to sinkpad.pull_range(..) leaks memory (all buffers are leaked). Steps to reproduce: The setup is as follows: fakesrc | puller | fakesink The puller element is written in Python (I'll attach code). This only happens when the puller element calls pull_range() - python sources with a pulling fakesink work correctly and pullers that don't call pull_range() (but instanaiate buffers themselves) work perfectly, too. Actual results: When executing with GST_DEBUG=5 one can that the buffers don't get unreffed enough and don't get freed, thus leaking a lot of memory. Expected results: Does this happen every time? Yes Other information:
Created attachment 119716 [details] Testcase Test case
Created attachment 119717 [details] Incomplete debug output A snippet from the debug output
I have also observed that the python Pullsource with a pulling fakesink also leaks memeory when allocating the buffer via pad.alloc_buffer_and_set_caps(...) (see code)
We've observed that when creating events, after creating the pygstminiobject_new, the original object is unreffed. Shouldn't this be also done in the functions in gstpad.override - like this: %% override gst_pad_pull_range kwargs static PyObject * _wrap_gst_pad_pull_range (PyGObject *self, PyObject * args, PyObject *kwargs) { static char *kwlist[] = {"offset", "size", NULL}; guint64 offset; gint size; PyObject *ret; GstBuffer *buf; GstFlowReturn res; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Ki:GstPad.pull_range", kwlist, &offset, &size)) return NULL; res = gst_pad_pull_range (GST_PAD(pygobject_get(self)), offset, size, &buf); ret = PyList_New(2); PyList_SetItem(ret, 0, pyg_enum_from_gtype(GST_TYPE_FLOW_RETURN, res)); if (res != GST_FLOW_OK) { PyList_SetItem(ret, 1, Py_None); } else { PyList_SetItem(ret, 1, pygstminiobject_new(GST_MINI_OBJECT(buf))); //unreffing original object like it is //done e.g. in _wrap_gst_event_new_custom gst_mini_object_unref(GST_MINI_OBJECT(buf)); } return ret; } When we unref this object, the memory leaks disappear. %%
confirmed, and we also have the same issue with the other gst_pad_get_range/gst_pad_alloc_buffer/... overrides that return a newly created buffer as a function argument.
2008-12-06 Edward Hervey <edward.hervey@collabora.co.uk> * gst/gstpad.override: Fix memory leak for functions that return a newly created buffer as a function argument. Fixes #554545