Crash happened when sink element unlink from nvstreammux dynamiclly

I construct the pipeline, like this “(appsrc -> queue )-> nvstreammux->nvinfer->faksink”.
At running time, I add a couple of “appsrc-queue” and linked to nvstreammux. it works well.But when I remove a couple of “appsrc-queue”, program crashed.
I code with the refertence “

Here is my code segment. Is there some wrong?

gst_element_set_state(queue, GST_STATE_NULL);
gst_element_get_state(queue, NULL, NULL, GST_CLOCK_TIME_NONE);
gst_element_set_state(appsrc, GST_STATE_NULL);
gst_element_get_state(appsrc, NULL, NULL, GST_CLOCK_TIME_NONE);
std::string sink_pad_name = “sink_”;
sink_pad_name += std::to_string(vid);
GstPad *sinkpad = gst_element_get_static_pad(mux_, sink_pad_name.c_str());
gst_pad_send_event(sinkpad, gst_event_new_flush_stop(FALSE));
gst_element_release_request_pad(mux_, sinkpad);
gst_bin_remove(GST_BIN(pipeline_), appsrc);
gst_bin_remove(GST_BIN(pipeline_), queue);

Hardware Platform (Jetson NX )
DeepStream Version 5.0

Here is the log.

###dec  id= 0
decode sink pts = 73970590339
0:01:43.906697401 28804   0x7ee8003630 WARN          v4l2bufferpool gstv4l2bufferpool.c:1491:gst_v4l2_buffer_pool_dqbuf:<nvv4l2decoder0:pool:sink> v4l2 provided buffer that is too big for the memory it was writing into.  v4l2 claims 64 bytes used but memory is only 0B.  This is probably a driver bug.
#####video handle  id= 0
alg_appsrc_map_ size = 1
elem = 0x7fac2b4810
rtp timestamp = 3997269800

Thread 35 "nvstreammux:src" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f328fac50 (LWP 28857)]
0x0000007fa75c5588 in ?? () from /usr/lib/aarch64-linux-gnu/tegra/
(gdb) bt
#0  0x0000007fa75c5588 in  () at /usr/lib/aarch64-linux-gnu/tegra/
#1  0x0000007fa75c9d00 in NvBufSurfTransform () at /usr/lib/aarch64-linux-gnu/tegra/
#2  0x0000007f8c8b63d8 in convert_batch_and_push_to_input_thread(GstNvInfer*, GstNvInferBatch*, GstNvInferMemory*) (nvinfer=0x7fac288dd0, batch=0x7ecc049de0, mem=0x7f0cb7a1c0) at gstnvinfer.cpp:1231
#3  0x0000007f8c8b6e34 in gst_nvinfer_process_full_frame(GstNvInfer*, GstBuffer*, NvBufSurface*) (nvinfer=0x7fac288dd0, inbuf=0x7ee404c440, in_surf=0x7f040080b0) at gstnvinfer.cpp:1355
#4  0x0000007f8c8b84a8 in gst_nvinfer_submit_input_buffer(GstBaseTransform*, gboolean, GstBuffer*) (btrans=0x7fac288dd0, discont=0, inbuf=0x7ee404c440) at gstnvinfer.cpp:1744
#5  0x0000007fb756886c in  () at /usr/lib/aarch64-linux-gnu/
(gdb) f 2
#2  0x0000007f8c8b63d8 in convert_batch_and_push_to_input_thread (nvinfer=0x7fac288dd0, batch=0x7ecc049de0, mem=0x7f0cb7a1c0)
at gstnvinfer.cpp:1231
1231        err = NvBufSurfTransform (&nvinfer->tmp_surf, mem->surf,

Sorry for a late reply,
Have you solved the issue?
You need to handle different state change of element appsrc.

I has avoided the problem. I found gstbuffer generated by rtsp-stream pipeline should be clear up at algrithm pipeline befor shuting down rtsp-stream pipeline. I do not know the root cause. It seems that two pipeline interact with each other through the runing gstbuffers.

Thanks for sharing.