From patchwork Thu Oct 10 03:40:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 15659 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id DCED744A020 for ; Thu, 10 Oct 2019 06:40:39 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C5CD96881B3; Thu, 10 Oct 2019 06:40:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbgeu2.qq.com (smtpbgeu2.qq.com [18.194.254.142]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 88AAA688074 for ; Thu, 10 Oct 2019 06:40:32 +0300 (EEST) X-QQ-mid: bizesmtp25t1570678827tmgrvjmb Received: from localhost (unknown [47.90.47.25]) by esmtp10.qq.com (ESMTP) with id ; Thu, 10 Oct 2019 11:40:27 +0800 (CST) X-QQ-SSF: 01100000002000K0ZRF1000A0000000 X-QQ-FEAT: TKaiDxUsqaZV+JbPhJXrFX1dDEnNJrRKlF3I2Q9xKksG/DJ+DdPfm+/ro/61c g0wTvAM1eeDGFnXdq3I66Co5qqEbZwLJ/2W/4ZQvnK6Huc5RyRFONxKEGzyyHAPL4KO2kdM ZNCUMhldHOEXDx5YbjO72HeLcc7Ky6r8NgY5xeYbr0GAKDvV8alIt+EwvfwWSjXje7imNin G/xhe3lKYyt2I+LsVubP8/xxWPiG6rUZzggkld8n8nhRG2ahvs1GBwE37vl0a2177uk/UNS 6Ie8ZSfv/6NSo7tfaH614dJCCrZuVAb+Jz8c7WoHx/W+je2AaH5DxL2uV0i8VjMRwdFA== X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Thu, 10 Oct 2019 11:40:07 +0800 Message-Id: <20191010034011.1205-4-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.10.1.382.ga23ca1b.dirty In-Reply-To: <20191010034011.1205-1-lq@chinaffmpeg.org> References: <20191010034011.1205-1-lq@chinaffmpeg.org> X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybgforeign:qybgforeign2 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH v1 4/8] avformat/libsrt: check av_strdup() return value and fix memleak X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Steven Liu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Steven Liu --- libavformat/libsrt.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c index b5568089fa..91e8c4b55b 100644 --- a/libavformat/libsrt.c +++ b/libavformat/libsrt.c @@ -478,6 +478,7 @@ static int libsrt_open(URLContext *h, const char *uri, int flags) SRTContext *s = h->priv_data; const char * p; char buf[256]; + int ret = 0; if (srt_startup() < 0) { return AVERROR_UNKNOWN; @@ -564,10 +565,18 @@ static int libsrt_open(URLContext *h, const char *uri, int flags) if (av_find_info_tag(buf, sizeof(buf), "streamid", p)) { av_freep(&s->streamid); s->streamid = av_strdup(buf); + if (!s->streamid) { + ret = AVERROR(ENOMEM); + goto err; + } } if (av_find_info_tag(buf, sizeof(buf), "smoother", p)) { av_freep(&s->smoother); s->smoother = av_strdup(buf); + if(!s->smoother) { + ret = AVERROR(ENOMEM); + goto err; + } } if (av_find_info_tag(buf, sizeof(buf), "messageapi", p)) { s->messageapi = strtol(buf, NULL, 10); @@ -578,11 +587,15 @@ static int libsrt_open(URLContext *h, const char *uri, int flags) } else if (!strcmp(buf, "file")) { s->transtype = SRTT_FILE; } else { - return AVERROR(EINVAL); + ret = AVERROR(EINVAL); + goto err; } } } return libsrt_setup(h, uri, flags); +err: + av_freep(&s->smoother); + av_freep(&s->streamid); } static int libsrt_read(URLContext *h, uint8_t *buf, int size)