From patchwork Wed Nov 4 20:47:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23395 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 8674344906D for ; Wed, 4 Nov 2020 22:47:16 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5D97B68B570; Wed, 4 Nov 2020 22:47:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DA4C768B570 for ; Wed, 4 Nov 2020 22:47:09 +0200 (EET) Received: by mail-wm1-f67.google.com with SMTP id h22so3607398wmb.0 for ; Wed, 04 Nov 2020 12:47:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6sWI/EXXdwIhBWgV//sjR/WOxEdzSrnl354cbDIYHxI=; b=QTpceNnPsFRMoZuB7Sz5MFdYr3IYvN6j8exVHHli9wiymw8Ca36DalH2INXnr35fcW aekDOoQoLoZ7t1Ed3UwUcYCWbuFVckRYW7mVqIk6f28og72DlYIpIez1iGxRFtngjMIe lMoko2j9AYq0qfdk13mcX6VyUz5xH+i1+O2KMjn4aoH1OlS6q8yHhGR/iNMikpFF6ErB wv8rv7LsKD4PgCEYUYOmO1OqJ5bHmCqg0QV3X+8ygWRroxyyFwuMK/NIoi5Sqr2BWwuR MvDY5rzxHqKhkVpp01BxsdFePZv9Cz/6BsJAs9QSZSL+qr/3Fa064hbHe6GkUD6kNeic OZwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6sWI/EXXdwIhBWgV//sjR/WOxEdzSrnl354cbDIYHxI=; b=mCGfBRbsmC4X4fUtcKREk0Yj+aTNVZp6oxQgk/U63VFoyh86UWHqpGWNB3y2H6JFfM sQD6Z3XoxyWLaJXxI2T/kmWc7roHqUpF0HlpGAU3Ib01Q88IlBVR+Gh8IIYGcMki5cGp 1JyHTQzP6R6f0getvRkWtbFxXbOd/LxJjH/bA1Bkgr7VA1htfF7n7CVZUEVC620jXzzS bQChmjqz5Z1ZBkdvDy6oVblr7mWuoTMjp4Q+HRZmCiuxZ4Wx6x2MZFSfI+UBAAppoV/t PnJlNDBa3nRmfasTA5tgOt66jk18C9RZ9qwbaDAXi56dGC+tkx3K/OfY4KkpKwhGEIA7 RUIA== X-Gm-Message-State: AOAM533ywpJWgoNgiNK++W8GmUsB4thwhsnIBd2McKlH3IQO1NDOVJni 6ndsdTsA3P7U1MrVnDzrEo+Jpgdw2pg= X-Google-Smtp-Source: ABdhPJyl6Q2g19XCrxfAPBZC5Mofr45JxjxQQg6aT0yDJ9/ZSM2gXVZwPZwBLeKoF+YWR3lZA63hfA== X-Received: by 2002:a7b:cbcf:: with SMTP id n15mr6418287wmi.156.1604522829007; Wed, 04 Nov 2020 12:47:09 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id v16sm3073698wml.33.2020.11.04.12.47.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 12:47:08 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 4 Nov 2020 21:47:02 +0100 Message-Id: <20201104204702.256762-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/mss4: Fix memleaks upon allocation error 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" During init the mts2 decoder allocates several VLCs and then several buffers in a loop; if one of the latter allocations fails, only the VLCs are freed, not any buffers that might already have been successfully allocated. This commit fixes this by setting the FF_CODEC_CAP_INIT_CLEANUP flag. Signed-off-by: Andreas Rheinhardt --- libavcodec/mss4.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libavcodec/mss4.c b/libavcodec/mss4.c index 432df294d6..c421a07c5d 100644 --- a/libavcodec/mss4.c +++ b/libavcodec/mss4.c @@ -648,7 +648,6 @@ static av_cold int mss4_decode_init(AVCodecContext *avctx) if (mss4_init_vlcs(c)) { av_log(avctx, AV_LOG_ERROR, "Cannot initialise VLCs\n"); - mss4_free_vlcs(c); return AVERROR(ENOMEM); } for (i = 0; i < 3; i++) { @@ -656,16 +655,13 @@ static av_cold int mss4_decode_init(AVCodecContext *avctx) c->prev_dc[i] = av_malloc_array(c->dc_stride[i], sizeof(**c->prev_dc)); if (!c->prev_dc[i]) { av_log(avctx, AV_LOG_ERROR, "Cannot allocate buffer\n"); - mss4_free_vlcs(c); return AVERROR(ENOMEM); } } c->pic = av_frame_alloc(); - if (!c->pic) { - mss4_decode_end(avctx); + if (!c->pic) return AVERROR(ENOMEM); - } avctx->pix_fmt = AV_PIX_FMT_YUV444P; @@ -682,4 +678,5 @@ AVCodec ff_mts2_decoder = { .close = mss4_decode_end, .decode = mss4_decode_frame, .capabilities = AV_CODEC_CAP_DR1, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, };