* buffer overflow detected *: terminated when a rtsp pipeline is created and destroyed many times

In the app, cameras need to be switched. In the switch, rtsp pipeline is stopped first, then destroyed and recreated. After about 150 switches with 4 cameras, the app crashes with the error message: * buffer overflow detected *: terminated.
What could be the root causes? How to fix the bug?
There is some memory leak. But the app crashes, memory usage is around 14%, still enough for the app to keep going.

There is not really enough information here. The bug might be in the application code.

There’s an rtspsrc2 in the Rust plugins for what it’s worth in case you want to give that a try.

Thank you for your reply. A script was applied to purely switch cameras in the pipeline class(destroy and recreate). No other operations are involved in the app for this test. The same Qt QML sinks are reused. The pad of rtspsrc is applied to detect streaming types(H264 or H265) before decoder + QML sink are added to the pipeline. Tried to set 100 to max-size-buffers of queue2 in the pipeline and no help. Also made sure that the pipeline is destroyed after the pad of rtspsrc is removed.

Added Asan in the debug build and could not find anything. It is impossible to use
valgrind to debug the app for now(too slow for update). May write a small Qt test code later for valgrind.

Gstreamer 1.22.5 + Qt 5.15.2 + Ubuntu 22.04. Can not upgrade any of them for now.

When cameras are switched, there are two ways to handle source change.

  1. delete the pipeline and rebuild a new one
  2. disconnect rtspsrc, delete it and create a new rtspsrc.
    Which one is preferred?

Tested. Number 2 is way better than number 1.
Able to make 5000 switches with number 2. No way to get such a large number of switches with number 1. But still some rare and random memory related crashes which can be traced to Intel media driver. Will try some newer versions later.