From 00587eb561c243745defc442f9b139e80a50ba92 Mon Sep 17 00:00:00 2001 From: "Reynaldo H. Verdejo Pinochet" Date: Tue, 29 Dec 2015 14:35:14 -0800 Subject: [PATCH] rtmpsrc: 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/gstrtmpsrc.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ext/rtmp/gstrtmpsrc.c b/ext/rtmp/gstrtmpsrc.c index 46918e755f..02cbec1d1c 100644 --- a/ext/rtmp/gstrtmpsrc.c +++ b/ext/rtmp/gstrtmpsrc.c @@ -575,13 +575,17 @@ gst_rtmp_src_start (GstBaseSrc * basesrc) src->discont = TRUE; src->rtmp = RTMP_Alloc (); + + if (!src->rtmp) { + GST_ERROR_OBJECT (src, "Could not allocate librtmp's RTMP context"); + goto error; + } + RTMP_Init (src->rtmp); if (!RTMP_SetupURL (src->rtmp, src->uri)) { GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), ("Failed to setup URL '%s'", src->uri)); - RTMP_Free (src->rtmp); - src->rtmp = NULL; - return FALSE; + goto error; } src->seekable = !(src->rtmp->Link.lFlags & RTMP_LF_LIVE); GST_INFO_OBJECT (src, "seekable %d", src->seekable); @@ -591,13 +595,18 @@ gst_rtmp_src_start (GstBaseSrc * basesrc) if (!RTMP_Connect (src->rtmp, NULL)) { GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), ("Could not connect to RTMP stream \"%s\" for reading", src->uri)); - RTMP_Free (src->rtmp); - src->rtmp = NULL; - return FALSE; + goto error; } } return TRUE; + +error: + if (src->rtmp) { + RTMP_Free (src->rtmp); + src->rtmp = NULL; + } + return FALSE; } #undef STR2AVAL