From d625770a18f68b1a1eee2a71810cb2fe692ecee9 Mon Sep 17 00:00:00 2001 From: Jose Antonio Santos Cadenas Date: Thu, 14 May 2015 16:06:55 +0200 Subject: [PATCH] dtls: Fix memory leak Keys were not correctly released when it was get as a property nor when a second key was received https://bugzilla.gnome.org/show_bug.cgi?id=749380 --- ext/dtls/gstdtlsdec.c | 6 ++++++ ext/dtls/gstdtlsenc.c | 6 ++++++ ext/dtls/gstdtlssrtpdec.c | 2 ++ ext/dtls/gstdtlssrtpenc.c | 2 ++ 4 files changed, 16 insertions(+) diff --git a/ext/dtls/gstdtlsdec.c b/ext/dtls/gstdtlsdec.c index 75c8275277..95ea6922cd 100644 --- a/ext/dtls/gstdtlsdec.c +++ b/ext/dtls/gstdtlsdec.c @@ -404,6 +404,12 @@ on_key_received (GstDtlsConnection * connection, gpointer key, guint cipher, self->srtp_auth = auth; key_dup = g_memdup (key, GST_DTLS_SRTP_MASTER_KEY_LENGTH); + + if (self->decoder_key) { + gst_buffer_unref (self->decoder_key); + self->decoder_key = NULL; + } + self->decoder_key = gst_buffer_new_wrapped (key_dup, GST_DTLS_SRTP_MASTER_KEY_LENGTH); diff --git a/ext/dtls/gstdtlsenc.c b/ext/dtls/gstdtlsenc.c index 96dfa54fc9..b78ff4a855 100644 --- a/ext/dtls/gstdtlsenc.c +++ b/ext/dtls/gstdtlsenc.c @@ -509,6 +509,12 @@ on_key_received (GstDtlsConnection * connection, gpointer key, guint cipher, self->srtp_auth = auth; key_dup = g_memdup (key, GST_DTLS_SRTP_MASTER_KEY_LENGTH); + + if (self->encoder_key) { + gst_buffer_unref (self->encoder_key); + self->encoder_key = NULL; + } + self->encoder_key = gst_buffer_new_wrapped (key_dup, GST_DTLS_SRTP_MASTER_KEY_LENGTH); diff --git a/ext/dtls/gstdtlssrtpdec.c b/ext/dtls/gstdtlssrtpdec.c index d80328d67e..a86a8d7085 100644 --- a/ext/dtls/gstdtlssrtpdec.c +++ b/ext/dtls/gstdtlssrtpdec.c @@ -381,6 +381,8 @@ on_decoder_request_key (GstElement * srtp_decoder, break; } + gst_buffer_unref (key_buffer); + return key_caps; } else { GST_WARNING_OBJECT (bin, "no srtp key available yet"); diff --git a/ext/dtls/gstdtlssrtpenc.c b/ext/dtls/gstdtlssrtpenc.c index d7055b85e0..941afacf5b 100644 --- a/ext/dtls/gstdtlssrtpenc.c +++ b/ext/dtls/gstdtlssrtpenc.c @@ -399,6 +399,8 @@ on_key_received (GObject * encoder, GstDtlsSrtpEnc * self) "rtp-auth", auth, "rtcp-auth", auth, "key", buffer, "random-key", FALSE, NULL); + gst_buffer_unref (buffer); + g_signal_emit (self, signals[SIGNAL_ON_KEY_SET], 0); } else { GST_DEBUG_OBJECT (self,