From patchwork Tue Jan 10 11:45:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 2168 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp218646vsb; Tue, 10 Jan 2017 03:45:44 -0800 (PST) X-Received: by 10.28.174.194 with SMTP id x185mr1615690wme.4.1484048744463; Tue, 10 Jan 2017 03:45:44 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r4si1275173wrr.238.2017.01.10.03.45.43; Tue, 10 Jan 2017 03:45:44 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 05EF068A46F; Tue, 10 Jan 2017 13:45:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbgau2.qq.com (smtpbgau2.qq.com [54.206.34.216]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5FC7A68A262 for ; Tue, 10 Jan 2017 13:45:26 +0200 (EET) X-QQ-mid: bizesmtp15t1484048724tgw5hovi Received: from localhost (unknown [47.90.47.25]) by esmtp4.qq.com (ESMTP) with id ; Tue, 10 Jan 2017 19:45:23 +0800 (CST) X-QQ-SSF: 01100000008000F0F621000A0000000 X-QQ-FEAT: QX/rXDl9P1twtf2O8oHWrY+VyrZUA7Uo2j2gtoqgapYmZZpIxcdKganY2DmCu 1L8h/A4IGu1OWk3wY1SCvZ5Oa9z7iaFdiVLoaIu+SvBTsaAx/5nITqe8zDPiMRnKuP21e3h grDNGX2ArEx0CoO0IEmPvLhQG2ymSW3IeikHNTV4VZal2DnOK0+AvEyTD+J/1T6gl0KP2It 0lulYEymnyqc5nPCtvD65himpbSY7gc/UlQlnd3ouMtUjFxaOS4ybqGgdwfUVsvHIJq5kf4 5LmisvAFh6S00T X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Jan 2017 19:45:22 +0800 Message-Id: <20170110114522.7626-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.10.1.382.ga23ca1b.dirty X-QQ-SENDSIZE: 520 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH 3/3] avfilter/vf_libopencv: fix resource leak in read_shape_frame_filter 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" CID: 1324298 add a label when error goto the label to release resource Signed-off-by: Steven Liu --- libavfilter/vf_libopencv.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c index f8ae9d5..8128030 100644 --- a/libavfilter/vf_libopencv.c +++ b/libavfilter/vf_libopencv.c @@ -157,7 +157,8 @@ static int read_shape_from_file(int *cols, int *rows, int **values, const char * if (buf[i] == '\n') { if (*rows == INT_MAX) { av_log(log_ctx, AV_LOG_ERROR, "Overflow on the number of rows in the file\n"); - return AVERROR_INVALIDDATA; + ret = AVERROR_INVALIDDATA; + goto end; } ++(*rows); *cols = FFMAX(*cols, w); @@ -171,10 +172,13 @@ static int read_shape_from_file(int *cols, int *rows, int **values, const char * if (*rows > (SIZE_MAX / sizeof(int) / *cols)) { av_log(log_ctx, AV_LOG_ERROR, "File with size %dx%d is too big\n", *rows, *cols); - return AVERROR_INVALIDDATA; + ret = AVERROR_INVALIDDATA; + goto end; + } + if (!(*values = av_mallocz_array(sizeof(int) * *rows, *cols))) { + ret = AVERROR(ENOMEM); + goto end; } - if (!(*values = av_mallocz_array(sizeof(int) * *rows, *cols))) - return AVERROR(ENOMEM); /* fill *values */ p = buf; @@ -188,6 +192,8 @@ static int read_shape_from_file(int *cols, int *rows, int **values, const char * (*values)[*cols*i + j] = !!av_isgraph(*(p++)); } } + +end: av_file_unmap(buf, size); #ifdef DEBUG