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.
This commit is contained in:
Reynaldo H. Verdejo Pinochet 2015-12-29 14:16:58 -08:00
parent 4b93a7167f
commit 17da1ad409

View file

@ -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