Pipeline manipulation as changing elements in a pipeline by removed and added element cause memory leak
Describe your issue
I have tried the example dynamic changing elements in a pipeline by removed and added element in every 1 second. I observer that RES and SHR memory increase overtime.
The tutorial sample code from the official Gstreamer page: Link tutorial
This issues is critical to our system if have a change dynamic in pipeline from a bin which is included a lot of child elements and repeate in many time. The application OOM and crash overtime.
Expected Behavior
The memory need to be stable when changing element in the pipeline
Observed Behavior
After running about 10 minute the RES and SHR memory increase overtime from 0.2% to 0.8% after 10 minutes.
Setup
- Operating System: 22.04
- Device: Computer
- GStreamer Version: 1.20.3
Steps to reproduce the bug
- open terminal
gcc add_delete.c $(pkg-config --cflags --libs gstreamer-1.0) -o add_delete
./add_delete
How reproducible is the bug?
Use htop
and check the percent memory take by ./add_delete
process overtime
Screenshots if relevant
Additional Information
Uncomment #define DEFAULT_EFFECTS "identity,exclusion"
Comment g_queue_push_tail (&effects, gst_object_ref (cur_effect));
to apply changing only 2 times of elements. build and run again. This is output of valgrind when running modified application.
Click to expand
valgrind --leak-check=yes ./add_delete
==290871== Memcheck, a memory error detector
==290871== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==290871== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==290871== Command: ./add_delete
==290871==
Adding effect 'identity'
Adding effect 'exclusion'
Adding effect 'navigationtest'
Adding effect 'agingtv'
Adding effect 'videoflip'
Adding effect 'vertigotv'
Adding effect 'gaussianblur'
Adding effect 'shagadelictv'
Adding effect 'edgetv'
Switching from 'identity0' to 'exclusion0'..
Switching from 'exclusion0' to 'navigationtest0'..
Switching from 'navigationtest0' to 'agingtv0'..
Switching from 'agingtv0' to 'videoflip0'..
Switching from 'videoflip0' to 'vertigotv0'..
Switching from 'vertigotv0' to 'gaussianblur0'..
==290871== Thread 4 queue0:src:
==290871== Conditional jump or move depends on uninitialised value(s)
==290871== at 0x48673D7: ??? (in /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstgaudieffects.so)
==290871== by 0x6CA8DD0: ??? (in /usr/lib/x86_64-linux-gnu/libgstvideo-1.0.so.0.2001.0)
==290871== by 0x63E3CB0: default_generate_output (gstbasetransform.c:2192)
==290871== by 0x63E314B: gst_base_transform_chain (gstbasetransform.c:2345)
==290871== by 0x49077CC: gst_pad_chain_data_unchecked (gstpad.c:4447)
==290871== by 0x490AD68: gst_pad_push_data (gstpad.c:4711)
==290871== by 0x490B18D: gst_pad_push (gstpad.c:4830)
==290871== by 0x63E321E: gst_base_transform_chain (gstbasetransform.c:2381)
==290871== by 0x49077CC: gst_pad_chain_data_unchecked (gstpad.c:4447)
==290871== by 0x490AD68: gst_pad_push_data (gstpad.c:4711)
==290871== by 0x490B18D: gst_pad_push (gstpad.c:4830)
==290871== by 0x6361874: UnknownInlinedFun (gstqueue.c:1388)
==290871== by 0x6361874: gst_queue_loop (gstqueue.c:1541)
==290871==
==290871== Conditional jump or move depends on uninitialised value(s)
==290871== at 0x48673DF: ??? (in /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstgaudieffects.so)
==290871== by 0x6CA8DD0: ??? (in /usr/lib/x86_64-linux-gnu/libgstvideo-1.0.so.0.2001.0)
==290871== by 0x63E3CB0: default_generate_output (gstbasetransform.c:2192)
==290871== by 0x63E314B: gst_base_transform_chain (gstbasetransform.c:2345)
==290871== by 0x49077CC: gst_pad_chain_data_unchecked (gstpad.c:4447)
==290871== by 0x490AD68: gst_pad_push_data (gstpad.c:4711)
==290871== by 0x490B18D: gst_pad_push (gstpad.c:4830)
==290871== by 0x63E321E: gst_base_transform_chain (gstbasetransform.c:2381)
==290871== by 0x49077CC: gst_pad_chain_data_unchecked (gstpad.c:4447)
==290871== by 0x490AD68: gst_pad_push_data (gstpad.c:4711)
==290871== by 0x490B18D: gst_pad_push (gstpad.c:4830)
==290871== by 0x6361874: UnknownInlinedFun (gstqueue.c:1388)
==290871== by 0x6361874: gst_queue_loop (gstqueue.c:1541)
==290871==
Switching from 'gaussianblur0' to 'shagadelictv0'..
Switching from 'shagadelictv0' to 'edgetv0'..
==290871==
==290871== HEAP SUMMARY:
==290871== in use at exit: 2,630,957 bytes in 25,990 blocks
==290871== total heap usage: 125,059 allocs, 99,069 frees, 36,987,677 bytes allocated
==290871==
==290871== Thread 1:
==290871== 384 bytes in 1 blocks are possibly lost in loss record 2,730 of 2,876
==290871== at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==290871== by 0x40147D9: calloc (rtld-malloc.h:44)
==290871== by 0x40147D9: allocate_dtv (dl-tls.c:375)
==290871== by 0x40147D9: _dl_allocate_tls (dl-tls.c:634)
==290871== by 0x4BF8834: allocate_stack (allocatestack.c:430)
==290871== by 0x4BF8834: pthread_create@@GLIBC_2.34 (pthread_create.c:647)
==290871== by 0x4AD29A4: g_system_thread_new (gthread-posix.c:1323)
==290871== by 0x4AD2C4A: UnknownInlinedFun (gthread.c:932)
==290871== by 0x4AD2C4A: g_thread_pool_start_thread.constprop.0 (gthreadpool.c:477)
==290871== by 0x4AB0482: g_thread_pool_push (gthreadpool.c:723)
==290871== by 0x493AB3B: default_push (gsttaskpool.c:111)
==290871== by 0x493A382: UnknownInlinedFun (gsttask.c:712)
==290871== by 0x493A382: gst_task_set_state_unlocked (gsttask.c:744)
==290871== by 0x493A47C: gst_task_set_state (gsttask.c:792)
==290871== by 0x490D366: gst_pad_start_task (gstpad.c:6306)
==290871== by 0x63E7E34: gst_base_src_perform_seek (gstbasesrc.c:1831)
==290871== by 0x63EB69E: gst_base_src_start_complete (gstbasesrc.c:3639)
==290871==
==290871== 384 bytes in 1 blocks are possibly lost in loss record 2,731 of 2,876
==290871== at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==290871== by 0x40147D9: calloc (rtld-malloc.h:44)
==290871== by 0x40147D9: allocate_dtv (dl-tls.c:375)
==290871== by 0x40147D9: _dl_allocate_tls (dl-tls.c:634)
==290871== by 0x4BF8834: allocate_stack (allocatestack.c:430)
==290871== by 0x4BF8834: pthread_create@@GLIBC_2.34 (pthread_create.c:647)
==290871== by 0x4AD29A4: g_system_thread_new (gthread-posix.c:1323)
==290871== by 0x4AD2C4A: UnknownInlinedFun (gthread.c:932)
==290871== by 0x4AD2C4A: g_thread_pool_start_thread.constprop.0 (gthreadpool.c:477)
==290871== by 0x4AB0482: g_thread_pool_push (gthreadpool.c:723)
==290871== by 0x48E5D53: gst_element_call_async (gstelement.c:3866)
==290871== by 0x48C483E: gst_bin_handle_message_func.lto_priv.0 (gstbin.c:3922)
==290871== by 0x48B7CBB: bin_bus_handler (gstbin.c:3252)
==290871== by 0x48D0861: gst_bus_post (gstbus.c:357)
==290871== by 0x48E65E9: gst_element_post_message_default.lto_priv.0 (gstelement.c:2117)
==290871== by 0x48E63B1: gst_element_post_message (gstelement.c:2160)
==290871==
==290871== 768 bytes in 2 blocks are possibly lost in loss record 2,763 of 2,876
==290871== at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==290871== by 0x40147D9: calloc (rtld-malloc.h:44)
==290871== by 0x40147D9: allocate_dtv (dl-tls.c:375)
==290871== by 0x40147D9: _dl_allocate_tls (dl-tls.c:634)
==290871== by 0x4BF8834: allocate_stack (allocatestack.c:430)
==290871== by 0x4BF8834: pthread_create@@GLIBC_2.34 (pthread_create.c:647)
==290871== by 0x4AD29A4: g_system_thread_new (gthread-posix.c:1323)
==290871== by 0x4AD2C4A: UnknownInlinedFun (gthread.c:932)
==290871== by 0x4AD2C4A: g_thread_pool_start_thread.constprop.0 (gthreadpool.c:477)
==290871== by 0x4AB0482: g_thread_pool_push (gthreadpool.c:723)
==290871== by 0x493AB3B: default_push (gsttaskpool.c:111)
==290871== by 0x493A382: UnknownInlinedFun (gsttask.c:712)
==290871== by 0x493A382: gst_task_set_state_unlocked (gsttask.c:744)
==290871== by 0x493A47C: gst_task_set_state (gsttask.c:792)
==290871== by 0x490D366: gst_pad_start_task (gstpad.c:6306)
==290871== by 0x6361FA1: gst_queue_src_activate_mode (gstqueue.c:1754)
==290871== by 0x490073E: activate_mode_internal (gstpad.c:1216)
==290871==
==290871== 3,909 (624 direct, 3,285 indirect) bytes in 1 blocks are definitely lost in loss record 2,828 of 2,876
==290871== at 0x4A06F9D: g_type_create_instance (gtype.c:1907)
==290871== by 0x49EDF4C: g_object_new_internal (gobject.c:2011)
==290871== by 0x49EF1AC: g_object_new_with_properties (gobject.c:2181)
==290871== by 0x48E9CCF: gst_element_factory_create_with_properties (gstelementfactory.c:494)
==290871== by 0x48EA531: gst_element_factory_make_with_properties (gstelementfactory.c:689)
==290871== by 0x10AEBE: main (in /data/tests/add_delete)
==290871==
==290871== LEAK SUMMARY:
==290871== definitely lost: 624 bytes in 1 blocks
==290871== indirectly lost: 3,285 bytes in 35 blocks
==290871== possibly lost: 1,536 bytes in 4 blocks
==290871== still reachable: 388,984 bytes in 3,092 blocks
==290871== suppressed: 2,123,448 bytes in 22,394 blocks
==290871== Reachable blocks (those to which a pointer was found) are not shown.
==290871== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==290871==
==290871== Use --track-origins=yes to see where uninitialised values come from
==290871== For lists of detected and suppressed errors, rerun with: -s
==290871== ERROR SUMMARY: 254 errors from 6 contexts (suppressed: 1 from 1)