Memory Leak with RTSP Server

Dwight Kulkarni dwight at
Tue Dec 14 17:30:03 UTC 2021

Hi all,

I have traced the problem to a specific area and was hoping for further

1) I have a main_gstreamer_pipeline with an appsink element.

2) On another thread, I have the RTSP server, which has an appsrc element
that hooks up to the appsink.

3) When the new client connects, there is a "media-configure" callback.

4) In this callback, I register for the "need-data" signal where I
"pull-sample" from appsink and then "push-buffer" onto the appsrc that is
driving the RTSP pipeline

5) Prior to registering for the "need-data" signal I have to stop the
main_gstreamer_pipeline, after registration I start the

6) If I do not stop and start the main pipeline the VLC client does not
work. I do not see a stream.

7) If I stop and start the main pipeline, the VLC client shows the stream
(the first time) but when I go to start the pipeline a second time on a
second VLC connection, it throws the segmentation fault below. The fault is
being thrown when I am stopping the main_gstreamer_pipeline() in

8) Maybe I should be stopping only the RTSP portion of the pipeline only
instead of the main gstreamer pipeline ?

To launch the RTSP pipeline I am using
rtsp_pipeline_config.c_str()); *
Not sure how to access the pipeline when it is created like this ?

9) I tried hooking up for the client-closed callback and cleanup the
session pool. Confirmed the call back is made when the client closes, but
didn't help. Not sure if it is even necessary ?

void client_closed_callback(GstRTSPClient *self, gpointer user_data){
    GstRTSPServer *server = GST_RTSP_SERVER(user_data);
    GstRTSPSessionPool *pool = gst_rtsp_server_get_session_pool(server);
    guint removed = gst_rtsp_session_pool_cleanup(pool);

Any help is appreciated. Thank you.

On Tue, Dec 14, 2021 at 10:08 AM Dwight Kulkarni <dwight at>

> Hello everyone,
> I am facing a strange behavior with my RTSP server setup and was hoping
> for any assistance.
> The issue is that I have an RTSP Server that starts on a thread.
> When no VLC client is connected, I check the memory and it is stable.
> When I connect the VLC client there is an initial jump in the memory usage
> of about 20-30 mb.
> Thereafter, the memory usage climbs by a few megs every 10-20 seconds and
> stabilizes around 80 mb.
> The problem seems to occur after I disconnect the VLC client by closing
> the window.
> The used up memory from the VLC connection is not released. If I try to
> connect with the VLC Client again, it gives me a segmentation fault and
> breaks the application. The message I get is:
> *(server:2331): GStreamer-CRITICAL **: 14:54:31.771: Trying to dispose
> element pipeline0, but it is in READY instead of the NULL state.You need to
> explicitly set elements to the NULL state beforedropping the final
> reference, to allow them to clean up.This problem may also be caused by a
> refcounting bug in theapplication or some element.Segmentation fault*
> It seems as if I need to dispose something which I am not presently doing
> when the client is disconnected. Maybe I need to stop the pipeline when no
> more clients are present ?
> Please see attached code.
> --
> Sincerely,
> Dwight Kulkarni


Dwight Kulkarni
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the gstreamer-devel mailing list