From 17da1ad409f7f03dc9962c053536489f46ce1967 Mon Sep 17 00:00:00 2001 From: "Reynaldo H. Verdejo Pinochet" Date: Tue, 29 Dec 2015 14:16:58 -0800 Subject: [PATCH] rtmpsink: check for failed RTMP context alloc Avoids an unlikely crash. Arguably, if allocation fails we have no chance of recovering but nonetheless, RTMP_Alloc can fail and librtmp's RTMP_init() (called next) assumes a non-NULL pointer is passed without checking. Additionally, unify exit path on error. --- ext/rtmp/gstrtmpsink.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ext/rtmp/gstrtmpsink.c b/ext/rtmp/gstrtmpsink.c index 095c6ef3d8..462ac4d068 100644 --- a/ext/rtmp/gstrtmpsink.c +++ b/ext/rtmp/gstrtmpsink.c @@ -162,15 +162,17 @@ gst_rtmp_sink_start (GstBaseSink * basesink) sink->rtmp_uri = g_strdup (sink->uri); sink->rtmp = RTMP_Alloc (); + + if (!sink->rtmp) { + GST_ERROR_OBJECT (sink, "Could not allocate librtmp's RTMP context"); + goto error; + } + RTMP_Init (sink->rtmp); if (!RTMP_SetupURL (sink->rtmp, sink->rtmp_uri)) { GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL), ("Failed to setup URL '%s'", sink->uri)); - RTMP_Free (sink->rtmp); - sink->rtmp = NULL; - g_free (sink->rtmp_uri); - sink->rtmp_uri = NULL; - return FALSE; + goto error; } GST_DEBUG_OBJECT (sink, "Created RTMP object"); @@ -182,6 +184,15 @@ gst_rtmp_sink_start (GstBaseSink * basesink) sink->have_write_error = FALSE; return TRUE; + +error: + if (sink->rtmp) { + RTMP_Free (sink->rtmp); + sink->rtmp = NULL; + } + g_free (sink->rtmp_uri); + sink->rtmp_uri = NULL; + return FALSE; } static gboolean