From patchwork Tue Oct 20 07:53:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23110 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 BA1FD44B69B for ; Tue, 20 Oct 2020 11:18:11 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 918B568B86B; Tue, 20 Oct 2020 11:18:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BB1A468B753 for ; Tue, 20 Oct 2020 11:18:04 +0300 (EEST) Received: by mail-lj1-f196.google.com with SMTP id y16so1080635ljk.1 for ; Tue, 20 Oct 2020 01:18:04 -0700 (PDT) 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=1FiXGdccTuOz7iwOpHq0BRSsjzFcgT/iL4wexrBGHjY=; b=ByjDJgrvqU8ad+A80PTzTo6h9aEBO+DzN+8vrnw9cMXtE1FtzbsqOu+gE3cOT+8U/t jlVtCiUugNFoXrbovEGrGhN5BdLEmeJVIgTrlwWGEejjJQZYZaNISlI+feQswqU7uwZZ /+kmVKdFFo97y3bZ4T7W6RGxeaI0L1NHnQykRX1J/Iyn258OQ+RG60NkuJKFaE2tUCki JCsVvOHyIRdQ/3RgP5wkM5CcY02o3OFe2koC2xz0tEhqH4Ms0l9+TVoz1UcgztZJ0Pbk T9pck36p2GJWIJ0BTXGHmSLYVGjJcl51N4kXtNyEiaDwqLWyN7ePrJbl/EwUQX10AtTh 4TUA== 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=1FiXGdccTuOz7iwOpHq0BRSsjzFcgT/iL4wexrBGHjY=; b=ohqXiKmbBBHyRg+EwhVggUEx/1qLQb7LGa5JD8V0SKSadHRPYZVESnB9pnHc/HvvRY ICRNAqOasMCW3IE6scXsjdsWOU2bi5VbXFscXRz9aVgZA+WHXx+UFrpAzEfb5kDlE9Br jtZnwwX7QLqY16kU+3PKLiSzbt/BZ49TJ7aK4ZkneQN/bpE5NT7slxQpecvRPO7KlgNf 2edo2S0ZSwKTJJBKHpYpljTJjZMjlakuk3ELL2k/F/lC83p6ar+Y8Vqg2V74IUyLb+Jb yd3AyuYrHFfnWNhaH8L1kosMkD4cOtv6GiGPOU+gkTdi8I1+RPggxGAXFXa3e0RdgQZ7 q0xQ== X-Gm-Message-State: AOAM533YFkvT2tgvMErDIWpCUXksZX33g4V6s2hx1HVXrVYH8InlwfS4 02q7EM3tRt1MuCr60qQ8vqHDF60iMGI= X-Google-Smtp-Source: ABdhPJy155NYhd3pgpWK7yTioKdBpnqa/uzdtvg4HnQ/PwSZIZQDINyx2IvjgQyfoMJCg+d8GxehGg== X-Received: by 2002:adf:a354:: with SMTP id d20mr2082148wrb.29.1603180444243; Tue, 20 Oct 2020 00:54:04 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id 130sm1533554wmd.18.2020.10.20.00.54.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Oct 2020 00:54:03 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 20 Oct 2020 09:53:52 +0200 Message-Id: <20201020075356.185676-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/vp3: Fix memleak upon init failure 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" Up until now, there was no cleanup in case initializing the Theora VLC tables failed, leading to memleaks. This commit gets rid of them by setting the FF_CODEC_CAP_INIT_CLEANUP flag for all decoders in vp3.c; this also allows to remove some (now redundant) cleanup code. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp3.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index 6fe1ca46a3..0d8d1ff80f 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -2287,7 +2287,6 @@ static av_cold int allocate_tables(AVCodecContext *avctx) !s->superblock_fragments || !s->macroblock_coding || !s->dc_pred_row || !s->motion_val[0] || !s->motion_val[1]) { - vp3_decode_end(avctx); return -1; } @@ -2302,12 +2301,8 @@ static av_cold int init_frames(Vp3DecodeContext *s) s->last_frame.f = av_frame_alloc(); s->golden_frame.f = av_frame_alloc(); - if (!s->current_frame.f || !s->last_frame.f || !s->golden_frame.f) { - av_frame_free(&s->current_frame.f); - av_frame_free(&s->last_frame.f); - av_frame_free(&s->golden_frame.f); + if (!s->current_frame.f || !s->last_frame.f || !s->golden_frame.f) return AVERROR(ENOMEM); - } return 0; } @@ -3221,7 +3216,8 @@ AVCodec ff_theora_decoder = { AV_CODEC_CAP_FRAME_THREADS, .flush = vp3_decode_flush, .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context), - .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | FF_CODEC_CAP_ALLOCATE_PROGRESS, + .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | FF_CODEC_CAP_ALLOCATE_PROGRESS | + FF_CODEC_CAP_INIT_CLEANUP, }; #endif @@ -3238,7 +3234,7 @@ AVCodec ff_vp3_decoder = { AV_CODEC_CAP_FRAME_THREADS, .flush = vp3_decode_flush, .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context), - .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS, + .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP, }; #if CONFIG_VP4_DECODER @@ -3255,6 +3251,6 @@ AVCodec ff_vp4_decoder = { AV_CODEC_CAP_FRAME_THREADS, .flush = vp3_decode_flush, .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context), - .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS, + .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP, }; #endif