From patchwork Thu Oct 10 05:23:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 15665 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 DD422449CC5 for ; Thu, 10 Oct 2019 08:23:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C4B4E687FA5; Thu, 10 Oct 2019 08:23:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbgbr2.qq.com (smtpbgbr2.qq.com [54.207.22.56]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1A41F687F71 for ; Thu, 10 Oct 2019 08:23:40 +0300 (EEST) X-QQ-mid: bizesmtp20t1570685014tko4o52e Received: from localhost (unknown [47.90.47.25]) by esmtp6.qq.com (ESMTP) with id ; Thu, 10 Oct 2019 13:23:34 +0800 (CST) X-QQ-SSF: 01100000002000K0ZRF1000A0000000 X-QQ-FEAT: Ksu+ipKsD1eaZqOiefLkTDPyBpsaqN085gaPWEhu/cV8/4tFgI2IBStQoWnxj adyTLwScSXJ8O7G+ate/y4HNTaJ6XhCUaWclJ3DP+IEWj89iZIp17FCyRWnh4sozGMWyHPA 53is6aLsNdnQWvKcgYOLpbbuvrVir54zmBY1dqgDSAxnt6wTCJLMxgwCrhT3Oc5+wCoJq3j eLrQerDGir+bMlAhvF1ppm9TGz0NZf9Ec19yfXjrdOvSjWBqf4iUU8C7h6oboVz8vVbvjA1 TH92APeb9ESKcztY6pe3O1ccuum+q5kk/KHaFM/wxPHIGP3VA3dv40UNKXEK7KjLXR7DRqI 8kwzlnN X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Thu, 10 Oct 2019 13:23:29 +0800 Message-Id: <20191010052329.4067-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.10.1.382.ga23ca1b.dirty In-Reply-To: References: X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybgforeign:qybgforeign4 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH v2] 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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libavformat/libsrt.c b/libavformat/libsrt.c index b5568089fa..1c34ec50b2 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,16 @@ 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); + return ret; } static int libsrt_read(URLContext *h, uint8_t *buf, int size)