GNOME Bugzilla – Bug 760982
adaptivedemux: memory leak of stream->internal_pad
Last modified: 2016-01-22 17:08:41 UTC
The function gst_adaptive_demux_stream_update_source() function creates a new GstPad called internal_pad. This pad is not freed when releasing the stream. You can reproduce this by running the dash_demux test under Valgrind. ==2414== 930 (528 direct, 402 indirect) bytes in 1 blocks are definitely lost in loss record 2,109 of 2,139 ==2414== at 0x5619493: g_type_create_instance (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4600.1) ==2414== by 0x55FB38A: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4600.1) ==2414== by 0x55FD224: g_object_new_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4600.1) ==2414== by 0x55FD590: g_object_new (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4600.1) ==2414== by 0xA4F8E72: gst_adaptive_demux_stream_update_source (gstadaptivedemux.c:2292) ==2414== by 0xA4F8E72: gst_adaptive_demux_stream_download_uri (gstadaptivedemux.c:2326) ==2414== by 0xA4FA16E: gst_adaptive_demux_stream_download_header_fragment (gstadaptivedemux.c:2451) ==2414== by 0xA4FA16E: gst_adaptive_demux_stream_download_fragment (gstadaptivedemux.c:2495) ==2414== by 0xA4FA16E: gst_adaptive_demux_stream_download_loop (gstadaptivedemux.c:2738) ==2414== by 0x535D550: gst_task_func (gsttask.c:331) ==2414== by 0x58AA2FD: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4600.1) ==2414== by 0x58A9964: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4600.1) ==2414== by 0x5D5D6A9: start_thread (pthread_create.c:333) This code was added in commit b7a0be23c6865286674ecac127bc4a1603437ee9 (https://bugzilla.gnome.org/show_bug.cgi?id=757951). Adding a free of internal_pad in gst_adaptive_demux_stream_free() does not work because the internal_pad has adaptivedemux set as its parent. I also tried removing the call to set the pad's parent, but that didn't work because that ended up with the chain function being called with freed data.
You could use GST_PAD_FLAG_NEED_PARENT on the pad, and unparent the pad before freeing. Would that help?
Created attachment 319562 [details] [review] adaptivedemux: fix leak of stream->internal_pad The function gst_adaptive_demux_stream_update_source() function creates a new GstPad called internal_pad. This pad is not freed when releasing the stream. My solution is to set GST_PAD_FLAG_NEED_PARENT so that the chain functions do not get called when the pad has no parent and then remove the parent in the gst_adaptive_demux_stream_free() function. This causes the refcount of the pad to be decremented to zero.
Attachment 319562 [details] pushed as cfb1b79 - adaptivedemux: fix leak of stream->internal_pad
(In reply to Sebastian Dröge (slomo) from comment #1) > You could use GST_PAD_FLAG_NEED_PARENT on the pad, and unparent the pad > before freeing. Would that help? Thanks Sebastian, that did indeed fix the problem.