GNOME Bugzilla – Bug 678015
gst-rtsp-server: issues found with valgrind
Last modified: 2012-06-14 08:25:04 UTC
When running gst-rtsp-server in valgrind, I've found some memory issues (leaks etc), which are explained below. 5 patches will be attached that are suggested fixes for those issues. PATCH #1: In gst_rtsp_media_factory_collect_streams: unref the srcpad that was retrieved using gst_element_get_static_pad. gst_ghost_pad_new will take one reference, and the other reference will otherwise give a memory leak. PATCH #2: Don't use g_object_unref on GstRTSPSessionMedia. GstRTSPSessionMedia is not a GObject type. When the GstRTSPSession is freed, it will free the media. PATCH #3: Changed session media iteration in rtsp-client.c, client_unlink_session: now don't iterate in session->medias list where items are removed by gst_rtsp_session_release_media. Instead, repeatedly remove the first item. PATCH #4: rtsp-client.c: free transport on no_stream in SETUP handler. PATCH #5: Avoid calling collect_media_stats from gst_rtsp_media_set_state when going to state GST_STATE_NULL. The motivation is a leak that can occur if a TEARDOWN request is handled right before shutting down and unreffing the GstRTSPServer. For the TEARDOWN, we have the following calls: handle_teardown_request gst_rtsp_session_media_set_state (GST_STATE_NULL) gst_rtsp_media_set_state (GST_STATE_NULL) collect_media_stats gst_element_query_duration The duration query can lead to a cached GST_QUERY_DURATION message in the pipeline GstBin. That message holds a reference to the pipeline, which gets a ref count of 2. Then, when the server is shut down, gst_rtsp_media_finalize gets called. Here, the media pipeline is unreffed. But the pipeline ref count is 2, so the pipeline is not freed. Patch #5 avoids this by not collecting media stats when going to GST_STATE_NULL. If I understand correctly, it is not an error to not collect media stats in this case.
Created attachment 216271 [details] [review] factory: plug pad leak in collect_streams
Created attachment 216273 [details] [review] rtsp-client: don't use g_object_unref on GstRTSPSessionMedia
Created attachment 216274 [details] [review] rtsp-client: changed session media iteration
Created attachment 216275 [details] [review] rtsp-client: free transport on no_stream in SETUP handler
Created attachment 216276 [details] [review] rtsp-media: don't collect media stats when going to NULL
pushed