From patchwork Mon Sep 14 05:27:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22355 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 BEA3F44A49B for ; Mon, 14 Sep 2020 08:28:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A706768BBD6; Mon, 14 Sep 2020 08:28:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7A82968BBAA for ; Mon, 14 Sep 2020 08:28:38 +0300 (EEST) Received: by mail-ed1-f67.google.com with SMTP id b12so16218350edz.11 for ; Sun, 13 Sep 2020 22:28:38 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=gknPRTCP5iUhIGmTLne9pMH7Q5fP0juZ/fXjiEG+JWQ=; b=SPIwKhIRor6+qWq4GPGGUWU3fNtVdXwV+iUi+v94QyjABkRWy7zAG0A64SMUY0X+Jm eAewCHW8/xZOxMLwIvcBz2TgCPR7Tg/bWaFg0/hdkqAuH1PgQZwye9xQ7EVPNojvqGJR OWoumuMeTTwpXl1B+0r8Fwgu3JXoy5TWUhtqp0hRGRLA3aSLvqFy+3nWTFE4NodMNwju AspeqjIZfIwpmiTxc5MCSLU9oE2U0DO+rfsKfkLz+L++ielqu4bQ6cAfxe4K3QFactGL VwuSJ6Tpdd1PBo2HK6TxXF8AjUoXjKqXotuM00eKyxkRp49H3gS0k6+tORt2WXnxQa5y Ca4w== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=gknPRTCP5iUhIGmTLne9pMH7Q5fP0juZ/fXjiEG+JWQ=; b=Cu9Lc+8H9dRoq/Leb1rZNtwstkvmuBKTNbQI1pyOaXEPmjpEBNJKGVQYRHcu7MQ3gk BlpuJxnqKv2IvNtlZovV+0CWn0eYhvA9XqUCQzBqcDkVW2LXBE7f5jxyRfBbgkfOReFw TWgSEX2jL1oCarhDK8acg6PFspb+MrZd1O0v5z4Y50cWIyh4vXu9cGYiH5HcIIiQ00gF f7Obz6S9tFGFFvE3lGZdAxgs/2Brh0MVJ2c/+aZCeUcgwOL6vrdlj9XpgMtw6GOVrHX+ iFaWsrrMiZ1HJNgforQZLSvZiar/8etCNgLirnJF2I/mtBHKwnPrImEC7RbZI9qyT0mQ Tntg== X-Gm-Message-State: AOAM531daNqI5HbGffREZJfcCxoL3VJw8MJtrYbVciRoWzTiNlsqyyjR aZEftrxlfoy65dW5ZYISDN/7X7Q5gjI= X-Google-Smtp-Source: ABdhPJylJBU0ZfF7xqNUoxV3AabM2kPq4WDVqO2Pfb8bLDYdjW3kEfm8yWze264BABUtmmFf9aEgBQ== X-Received: by 2002:aa7:cb05:: with SMTP id s5mr15264835edt.212.1600061317681; Sun, 13 Sep 2020 22:28:37 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id f4sm8251421edm.76.2020.09.13.22.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 22:28:36 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 14 Sep 2020 07:27:46 +0200 Message-Id: <20200914052747.124118-23-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200913025753.274772-1-andreas.rheinhardt@gmail.com> References: <20200913025753.274772-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 39/40] avcodec/ffv1: Simplify cleanup after allocation 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" Now that ff_ffv1_close() for both the FFV1 encoder and decoder, the code contained therein can be used to free the partially allocated slice contexts if allocating the slice contexts failed. One just has to set the correct number of slice contexts on error. This allows to remove the code for freeing partially allocated slice contexts in ff_ffv1_init_slice_contexts(). Signed-off-by: Andreas Rheinhardt --- libavcodec/ffv1.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 5b52849400..1c580c3b49 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -119,7 +119,7 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) av_assert0(max_slice_count > 0); - for (i = 0; i < max_slice_count; i++) { + for (i = 0; i < max_slice_count;) { int sx = i % f->num_h_slices; int sy = i / f->num_h_slices; int sxs = f->avctx->width * sx / f->num_h_slices; @@ -131,7 +131,7 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) if (!fs) goto memfail; - f->slice_context[i] = fs; + f->slice_context[i++] = fs; memcpy(fs, f, sizeof(*fs)); memset(fs->rc_stat2, 0, sizeof(fs->rc_stat2)); @@ -144,22 +144,14 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) sizeof(*fs->sample_buffer)); fs->sample_buffer32 = av_malloc_array((fs->width + 6), 3 * MAX_PLANES * sizeof(*fs->sample_buffer32)); - if (!fs->sample_buffer || !fs->sample_buffer32) { - av_freep(&fs->sample_buffer); - av_freep(&fs->sample_buffer32); - av_freep(&f->slice_context[i]); + if (!fs->sample_buffer || !fs->sample_buffer32) goto memfail; - } } f->max_slice_count = max_slice_count; return 0; memfail: - while(--i >= 0) { - av_freep(&f->slice_context[i]->sample_buffer); - av_freep(&f->slice_context[i]->sample_buffer32); - av_freep(&f->slice_context[i]); - } + f->max_slice_count = i; return AVERROR(ENOMEM); }