After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 753539 - mts: fix memory leak for files with embedded subtitles
mts: fix memory leak for files with embedded subtitles
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
git master
Other Linux
: Normal normal
: 1.5.90
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-08-12 04:20 UTC by Vineeth
Modified: 2015-11-24 14:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
fix memory leak (3.95 KB, patch)
2015-08-12 04:22 UTC, Vineeth
none Details | Review
fix event leak (1.29 KB, patch)
2015-08-13 01:34 UTC, Vineeth
committed Details | Review
fix buffer leak (1.74 KB, patch)
2015-08-13 01:35 UTC, Vineeth
committed Details | Review

Description Vineeth 2015-08-12 04:20:51 UTC
When playing mts files, there is a memory leak while linking post-colorspace with renderer elements. This happens because this is being done before pre-colorspace is linked with renderer. Hence creating and linking pre-colorspace before post-colorspace


==17522== 128 bytes in 2 blocks are definitely lost in loss record 6,337 of 6,644
==17522==    at 0x402C17C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==17522==    by 0x43D4BE2: g_malloc (in /lib/i386-linux-gnu/libglib-2.0.so.0.4002.0)
==17522==    by 0x43EB281: g_slice_alloc (in /lib/i386-linux-gnu/libglib-2.0.so.0.4002.0)
==17522==    by 0x43EB79C: g_slice_alloc0 (in /lib/i386-linux-gnu/libglib-2.0.so.0.4002.0)
==17522==    by 0x426B8E5: gst_event_new_custom (gstevent.c:299)
==17522==    by 0x426DE23: gst_event_new_reconfigure (gstevent.c:1376)
==17522==    by 0x4288FA4: gst_pad_link_full (gstpad.c:2432)
==17522==    by 0x428942A: gst_pad_link (gstpad.c:2487)
==17522==    by 0x716A709: _link_renderer (gstsubtitleoverlay.c:848)
==17522==    by 0x716D560: _pad_blocked_cb (gstsubtitleoverlay.c:1258)
==17522==    by 0x427CF9B: probe_hook_marshal (gstpad.c:3340)
==17522==    by 0x43BFBF9: g_hook_list_marshal (in /lib/i386-linux-gnu/libglib-2.0.so.0.4002.0)
==17522==    by 0x4235F1B: do_probe_callbacks (gstpad.c:3478)
==17522==    by 0x427E6D2: gst_pad_push_event_unchecked (gstpad.c:5034)
==17522==    by 0x427E8D7: push_sticky (gstpad.c:3653)
==17522==    by 0x427C766: events_foreach (gstpad.c:590)
==17522==    by 0x428889A: gst_pad_push_event (gstpad.c:3709)
==17522==    by 0x4288A18: event_forward_func (gstpad.c:2886)
==17522==    by 0x42848D2: gst_pad_forward (gstpad.c:2840)
==17522==    by 0x4284A3A: gst_pad_event_default (gstpad.c:2937)
Comment 1 Vineeth 2015-08-12 04:22:10 UTC
Created attachment 309094 [details] [review]
fix memory leak
Comment 2 Luis de Bethencourt 2015-08-12 13:29:43 UTC
I can't reproduce this memory leak.

Have a pipeline you can suggest to trigger the bug?
Comment 3 Vineeth 2015-08-13 01:23:18 UTC
   Any mts file with embedded subtitles will do..

   I tested with a file downloaded from https://archive.org/details/scm-10794-mtstestfile, named H.264/MPEG2-TS

G_SLICE=always-malloc GST_DEBUG=gc-friendly valgrind --tool=memcheck --leak-check=full --show-leak-kinds=definite --trace-children=yes --suppressions=gstreamer/common/gst.supp gst-play-1.0 /home/vineethtm/gst/master/00007.mts

   There are basically three different leaks.

1) This is mentioned above.

   This leak happens because in gstdvdspu.c, gst_dvd_spu_src_event, peer of sink pad is being checked and if present it is forwarded. Without the change in above patch sink pad wont be present and hence the event will be leaked.
   This can simply be fixed by unref'ing the event in else case. I am attaching patch next for this as well. I feel both the patches are needed and valid. Because it is always better to create and link the sink pad to renderer(dvdspu here) first and then create the src pad.


2) Leak of buffer.
==29969== 54,148 (3,876 direct, 50,272 indirect) bytes in 51 blocks are definitely lost in loss record 6,555 of 6,562
==29969==    at 0x402C17C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==29969==    by 0x433EBE2: g_malloc (in /lib/i386-linux-gnu/libglib-2.0.so.0.4002.0)
==29969==    by 0x4355281: g_slice_alloc (in /lib/i386-linux-gnu/libglib-2.0.so.0.4002.0)
==29969==    by 0x4185E7F: gst_memory_new_wrapped (gstallocator.c:391)
==29969==    by 0x4190C94: gst_buffer_new_wrapped_full (gstbuffer.c:858)
==29969==    by 0x4190E04: gst_buffer_new_wrapped (gstbuffer.c:883)
==29969==    by 0x6EF87F6: gst_ts_demux_push_pending_data (tsdemux.c:2180)
==29969==    by 0x6EFB2B3: gst_ts_demux_push (tsdemux.c:2316)
==29969==    by 0x6EF34E8: mpegts_base_chain (mpegtsbase.c:1145)
==29969==    by 0x6EF3765: mpegts_base_loop (mpegtsbase.c:1322)
==29969==    by 0x41FE4C8: gst_task_func (gsttask.c:331)
==29969==    by 0x41FF66E: default_func (gsttaskpool.c:68)

This happens because in gstspu-pgs, gstspu_exec_pgs_buffer()
buffer is being mapped, but not being unmapped.
Attaching a patch for this as well.



3) Leak related to deinterlace/ORC
==6292== 40 bytes in 1 blocks are definitely lost in loss record 4,782 of 6,558
==6292==    at 0x402C17C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==6292==    by 0x145BC4E6: orc_program_new (in /usr/lib/i386-linux-gnu/liborc-0.4.so.0.18.0)
==6292==    by 0x145BC534: orc_program_new_from_static_bytecode (in /usr/lib/i386-linux-gnu/liborc-0.4.so.0.18.0)
==6292==    by 0x145855ED: deinterlace_line_linear (tmp-orc.c:478)
==6292==    by 0x14584884: deinterlace_scanline_linear_planar_y_c (linear.c:54)
==6292==    by 0x14554BFB: gst_deinterlace_simple_method_deinterlace_frame_planar_plane (gstdeinterlacemethod.c:511)
==6292==    by 0x14555AF2: gst_deinterlace_simple_method_deinterlace_frame_planar (gstdeinterlacemethod.c:557)
==6292==    by 0x1455522E: gst_deinterlace_method_deinterlace_frame (gstdeinterlacemethod.c:199)
==6292==    by 0x1454EE35: gst_deinterlace_output_frame (gstdeinterlace.c:1914)
==6292==    by 0x145532AE: gst_deinterlace_chain (gstdeinterlace.c:2075)
==6292==    by 0x41C961F: gst_pad_push_data (gstpad.c:4040)
==6292==    by 0x464E625: gst_base_transform_chain (gstbasetransform.c:2372)

Not sure how to fix this. This might be related to orc and probably needs to be supressed.
Comment 4 Vineeth 2015-08-13 01:34:47 UTC
Created attachment 309186 [details] [review]
fix event leak
Comment 5 Vineeth 2015-08-13 01:35:04 UTC
Created attachment 309187 [details] [review]
fix buffer leak
Comment 6 Tim-Philipp Müller 2015-08-13 13:43:57 UTC
Comment on attachment 309186 [details] [review]
fix event leak

commit 0812437293fb628fa7bd8d7d478efd24c26b239b
Author: Vineeth TM <vineeth.tm@samsung.com>
Date:   Thu Aug 13 10:25:52 2015 +0900

    dvdspu: Fix event leaks
    
    When playing mts files with embedded subtitles, there are few event leaks.
    Events are supposed to be transfer full. So if not forwarding the event,
    they need to be freed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=753539
Comment 7 Tim-Philipp Müller 2015-08-13 13:57:29 UTC
Comment on attachment 309187 [details] [review]
fix buffer leak

Pushed with two minor changes (no need to init 'remaining' variable; use explicit cast when assigning pointer diff result to integer to avoid possible compiler warnings).

commit 6fb346717be1eb8b7d44b340eb418f1536365888
Author: Vineeth TM <vineeth.tm@samsung.com>
Date:   Thu Aug 13 10:31:20 2015 +0900

    spu-pgs: fix buffer and event leak
    
    When playing mts files with embedded subtitles, the buffer is mapped,
    but not unmapped at the end resulting in a memory leak.
    
    Also unref event in handle_dvd_event as it takes ownership of the event.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=753539
Comment 8 Vineeth 2015-11-23 04:42:49 UTC
Since the other change is cosmetic change and is not exactly needed for this bug, resolving this issue.