Memory leak use Gstreamer decode H264

Describe
I use GStreamer to decode H264 streams,When there is a break in decoding(e.g:network problems or RTSP streams shutdown…),i will close this pipline(pipline status:PLAYING->NULL) and try to reconnect,but memory leaks.
Setup

  • NVIDIA Jetson Xavier NX -Jetpack 4.4[L4T 32.4.3] and Jetpack 4.6
  • GStreamer 1.14.5
    pipline
  • “rtspsrc location=” + (rtsp address) + " ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv ! video/x-raw,format=(string)BGRx ! videoconvert ! appsink name=autovideosink"
  • “rtspsrc location=” + (rtsp address) + " ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvidconv ! video/x-raw,format=(string)BGRx ! videoconvert ! appsink name=autovideosink"
    test code
  • Test code referenced from GitHub - olibartfast/object-detection-inference: Object detection inference from rtsp ip camera stream using gstreamer ,The pipeline setup is as follows:
    sink_ = gst_bin_get_by_name (GST_BIN (pipeline_), "autovideosink");
	gst_app_sink_set_emit_signals((GstAppSink*)sink_, true);  
	gst_app_sink_set_drop((GstAppSink*)sink_, true);  
	gst_app_sink_set_max_buffers((GstAppSink*)sink_, 1);  
	static GstAppSinkCallbacks callbacks_ = { NULL, new_preroll, new_sample };  
	gst_app_sink_set_callbacks (GST_APP_SINK(sink_), &callbacks_, NULL, NULL); 
  • I use valgrind and view jtop tools discovered memory leak.some logs:

==25957== 58 bytes in 1 blocks are definitely lost in loss record 27 of 95
==25957== at 0x48450F8: malloc (vg_replace_malloc.c:309)
==25957== by 0x401300B: _dl_exception_create (dl-exception.c:77)
==25957== by 0x527AADB: _dl_signal_error (dl-error-skeleton.c:117)
==25957== by 0x400828B: _dl_map_object (dl-load.c:2384)
==25957== by 0x401173F: dl_open_worker (dl-open.c:235)
==25957== by 0x527AB6B: _dl_catch_exception (dl-error-skeleton.c:196)
==25957== by 0x40112D7: _dl_open (dl-open.c:605)
==25957== by 0x5397013: dlopen_doit (dlopen.c:66)
==25957== by 0x527AB6B: _dl_catch_exception (dl-error-skeleton.c:196)
==25957== by 0x527AC0F: _dl_catch_error (dl-error-skeleton.c:215)
==25957== by 0x5398777: _dlerror_run (dlerror.c:162)
==25957== by 0x53970E7: dlopen@@GLIBC_2.17 (dlopen.c:87)

==25957== 24,857 (24,798 direct, 59 indirect) bytes in 43 blocks are definitely lost in loss record 89 of 95
==25957== at 0x48450F8: malloc (vg_replace_malloc.c:309)
==25957== by 0x4A6C57F: g_malloc (in /usr/lib/aarch64-linux-gnu/libglib-2.0.so.0.5600.4)

==25957== LEAK SUMMARY:
==25957== definitely lost: 24,856 bytes in 44 blocks
==25957== indirectly lost: 59 bytes in 1 blocks
==25957== possibly lost: 6,532 bytes in 71 blocks
==25957== still reachable: 2,246,215 bytes in 29,650 blocks
==25957== of which reachable via heuristic:
==25957== length64 : 3,152 bytes in 68 blocks
==25957== newarray : 1,936 bytes in 41 blocks
==25957== suppressed: 0 bytes in 0 blocks
==25957==
==25957== ERROR SUMMARY: 16944812 errors from 102 contexts (suppressed: 0 from 0)
==25957==
==25957== 1 errors in context 1 of 102:
==25957== Thread 18 omxh264dec-omxh2:
==25957== Use of uninitialised value of size 8
==25957== at 0x765FFE8: NvBufferSetFdMapping (in /usr/lib/aarch64-linux-gnu/tegra/libnvbuf_fdmap.so.1.0.0)
==25957== by 0x75A7C1F: ExtractFdFromNvBuffer (in /usr/lib/aarch64-linux-gnu/tegra/libnvbuf_utils.so.1.0.0)
==25957== by 0x754A9D3: ??? (in /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstomx.so)
==25957== by 0x48CEFF7: ??? (in /usr/lib/aarch64-linux-gnu/libgstreamer-1.0.so.0.1405.0)
==25957== Uninitialised value was created by a heap allocation
==25957== at 0x48450F8: malloc (vg_replace_malloc.c:309)
==25957== by 0x7DA9EEF: ??? (in /usr/lib/aarch64-linux-gnu/tegra/libnvomx.so)
==25957== by 0x754228F: ??? (in /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstomx.so)
==25957== by 0x75422D7: ??? (in /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstomx.so)
==25957== by 0x754BE6B: ??? (in /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstomx.so)
==25957== by 0x754DDBF: ??? (in /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstomx.so)
==25957== by 0x4942EB3: ??? (in /usr/lib/aarch64-linux-gnu/libgstreamer-1.0.so.0.1405.0)
==25957==
==25957==
==25957== 1 errors in context 2 of 102:
==25957== Thread 13 rtpjitterbuffer0:
==25957== Invalid read of size 4
==25957== at 0x4903958: gst_mini_object_unref (in /usr/lib/aarch64-linux-gnu/libgstreamer-1.0.so.0.1405.0)
==25957== Address 0x8538608 is 8 bytes inside a block of size 72 free’d
==25957== at 0x4846360: free (vg_replace_malloc.c:540)
==25957== by 0x7552093: ??? (in /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstomx.so)
==25957== by 0x720316F: ??? (in /usr/lib/aarch64-linux-gnu/libgstvideo-1.0.so.0.1405.0)
==25957== Block was alloc’d at
==25957== at 0x48450F8: malloc (vg_replace_malloc.c:309)
==25957== by 0x4A6C57F: g_malloc (in /usr/lib/aarch64-linux-gnu/libglib-2.0.so.0.5600.4)
==25957==
==25957==
==25957== 1 errors in context 3 of 102:
==25957== Invalid read of size 4
==25957== at 0x4934F6C: gst_structure_copy (in /usr/lib/aarch64-linux-gnu/libgstreamer-1.0.so.0.1405.0)
==25957== Address 0x8538908 is 8 bytes inside a block of size 40 free’d
==25957== at 0x4846360: free (vg_replace_malloc.c:540)
==25957== by 0x4A367A7: ??? (in /usr/lib/aarch64-linux-gnu/libglib-2.0.so.0.5600.4)
==25957== Block was alloc’d at
==25957== at 0x48450F8: malloc (vg_replace_malloc.c:309)
==25957== by 0x4A6C57F: g_malloc (in /usr/lib/aarch64-linux-gnu/libglib-2.0.so.0.5600.4)

test script

  • valgrind --tool=memcheck --leak-check=full --show-reachable=yes --track-origins=yes --error-limit=no --log-file=memchk.log -v ./object-detection-inference --link=“rtsp://…”

Hi,
Please use nvv4l2decoder since we have deprecated omx plugins. And after changing to NULL state, please unref the pipeline and re-initialize a new one.

There is a know memory leak. Please apply this patch and rebuild/replace the plugin:
Jetson/L4T/r32.6.x patches - eLinux.org
[gstreamer] Memory leak in UDP streaming

Hi,thank you for your replies very much
I’ve already tried nvv4l2decoder,but there are still memory leaks. i see in this link Jetson Nano shows 100% CPU Usage after 30 minutes with Deepstream-app demo - #3 by vincent.mcgarry and downloaded libgstnvvideo4linux2 .so by vincent provided, It works. but this .so is on the Nano platform, i don’t know if there’s something wrong with it.
Because I am new to this,i don’t konw how to use this patch and rebuild gst-v4l2,please give me some advice,thank you

Hi,
Please download this package:
https://developer.nvidia.com/embedded/l4t/r32_release_v6.1/sources/t186/public_sources.tbz2

All source codes are in the package.

Hi,
Does this package still need to be patched?Thank you

Hi,

Yes, it is required to apply the patch and rebuild libgstnvvideo4linux2.so

Sorry for the late reply.
I use the package you provided( [t186/public_sources.tbz2] and this patch( DS40X_TEST_0001-gstv4l2dec-Fix-high-CPU-usage-in-drop-frame.zip),but there has conflict.
I was only able to patch it(https://developer.nvidia.com/embedded/r32-2-3_Release_v1.0/Sources/T186/public_sources.tbz2) successfully .
Is my method wrong or there has a new patch pack?thank you

Hi,
On later releases, you only need to apply this patch:
Jetson/L4T/r32.6.x patches - eLinux.org
[gstreamer] Memory leak in UDP streaming

This is not required:
Jetson Nano shows 100% CPU Usage after 30 minutes with Deepstream-app demo - #13 by DaneLLL

Sorry for the late reply.
I will try it,thank you.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.