From 52c0763042233f6173cc1dc77c3b9993c5184e62 Mon Sep 17 00:00:00 2001 From: Branko Subasic Date: Fri, 18 Feb 2022 16:05:53 +0100 Subject: [PATCH] gst-rtsp-server: Plug a few memory leaks in tests Found and fixed a few memory leaks in the gst_rtspserver, gst_onvif and gst_stream tests by running the tests in valgrind. Part-of: --- .../gst-rtsp-server/tests/check/gst/onvif.c | 17 +++++++++++++++++ .../tests/check/gst/rtspserver.c | 3 +++ .../gst-rtsp-server/tests/check/gst/stream.c | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/subprojects/gst-rtsp-server/tests/check/gst/onvif.c b/subprojects/gst-rtsp-server/tests/check/gst/onvif.c index 087a2f7983..4014f421af 100644 --- a/subprojects/gst-rtsp-server/tests/check/gst/onvif.c +++ b/subprojects/gst-rtsp-server/tests/check/gst/onvif.c @@ -111,6 +111,9 @@ GType test_src_get_type (void); #define test_src_parent_class parent_class G_DEFINE_TYPE (TestSrc, test_src, GST_TYPE_PUSH_SRC); +#define TEST_SRC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), test_src_get_type(), TestSrc)) + #define ROUND_UP_TO_10(x) (((x + 10 - 1) / 10) * 10) #define ROUND_DOWN_TO_10(x) (x - (x % 10)) @@ -241,6 +244,17 @@ test_src_init (TestSrc * src) src->ntp_offset = GST_CLOCK_TIME_NONE; } +static void +test_src_finalize (GObject * obj) +{ + TestSrc *src = TEST_SRC (obj); + + if (src->segment != NULL) + gst_segment_free (src->segment); + + G_OBJECT_CLASS (test_src_parent_class)->finalize (obj); +} + /* * We support seeking, both this method and GstBaseSrc.do_seek must * be implemented for GstBaseSrc to report TRUE in the seeking query. @@ -304,6 +318,8 @@ test_src_event (GstBaseSrc * bsrc, GstEvent * event) static void test_src_class_init (TestSrcClass * klass) { + G_OBJECT_CLASS (klass)->finalize = test_src_finalize; + gst_element_class_add_static_pad_template (GST_ELEMENT_CLASS (klass), &test_src_template); GST_PUSH_SRC_CLASS (klass)->create = test_src_create; @@ -457,6 +473,7 @@ test_response_x_onvif_track (GstRTSPClient * client, GstRTSPMessage * response, fail_unless_equals_string (gst_sdp_media_get_attribute_val (smedia, "x-onvif-track"), x_onvif_track); + g_free (x_onvif_track); } gst_sdp_message_free (sdp); diff --git a/subprojects/gst-rtsp-server/tests/check/gst/rtspserver.c b/subprojects/gst-rtsp-server/tests/check/gst/rtspserver.c index ed2cce233f..ecbbb25ad1 100644 --- a/subprojects/gst-rtsp-server/tests/check/gst/rtspserver.c +++ b/subprojects/gst-rtsp-server/tests/check/gst/rtspserver.c @@ -2401,6 +2401,8 @@ GST_START_TEST (test_record_tcp) stop_server (); iterate (); g_free (session); + /* release the reference to server_sink, obtained in media_constructed_cb */ + gst_object_unref (server_sink); } GST_END_TEST; @@ -2698,6 +2700,7 @@ GST_START_TEST (test_double_play) stop_server (); iterate (); + g_object_unref (client); } GST_END_TEST; diff --git a/subprojects/gst-rtsp-server/tests/check/gst/stream.c b/subprojects/gst-rtsp-server/tests/check/gst/stream.c index 3da4f9b25c..3dd1201674 100644 --- a/subprojects/gst-rtsp-server/tests/check/gst/stream.c +++ b/subprojects/gst-rtsp-server/tests/check/gst/stream.c @@ -632,8 +632,8 @@ add_transports (gboolean add_twice) fail_if (gst_rtsp_stream_remove_transport (stream, tr)); } - fail_unless (gst_rtsp_transport_free (transport) == GST_RTSP_OK); fail_unless (gst_rtsp_stream_leave_bin (stream, bin, rtpbin)); + g_object_unref (tr); gst_object_unref (bin); gst_object_unref (stream); }