From patchwork Sat Aug 8 14:01:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21539 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 E6665449249 for ; Sat, 8 Aug 2020 17:09:10 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BC15A68B861; Sat, 8 Aug 2020 17:09:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2C17F68B4C4 for ; Sat, 8 Aug 2020 17:09:04 +0300 (EEST) Received: by mail-ej1-f66.google.com with SMTP id g19so4933205ejc.9 for ; Sat, 08 Aug 2020 07:09: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=W2WuJYCNoiz90Ht0bI+esB09N1oAZb5wJH0eQJPSvjU=; b=MEQUrz13XcS87pWOpQDsoKashA3/UvuAfM5eJ2LGzjBAYxn0O4SKZ5+8GBON7IwRAK f7OCwt+dP129Y2A1GInOfqohn8OHvPzaCVh/y6az/XVjGDLL4lsOI3hQgqEAIRA4+7HO aw3wvjLZNqI7Z2QlRKitdmLygbBR0EXjErMZGYrfUkYtLChI+kycucHiNg8A0amP66Xd wOBvCG3CiXbiWfMaENRnMQwmLiW4+OAWnT75hZNC7ReC1uNyo5XJ/xL04JWWgijSogC4 c85L6iUaH2VUX/V2U0kmetWrUaPHCC7CJ9XkwgUPMa1uPcSbKzyiFVcJXEzXYzl1B69d U3Ww== 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=W2WuJYCNoiz90Ht0bI+esB09N1oAZb5wJH0eQJPSvjU=; b=KxPXs0N0OTpXG/7r1Ce+h+NtPmgwoUoqePcyfPZOvID6sYhaYPw7gERD3YbjrTMYEI Hwgs7S4L/5IRGXYPzei6K/H/1auUi6T5snQOcWSvAfad8Ts7D//YsTbEe+XfIYUNb/Je /FiRusNUcCpp77NqHZOx+2QwKv67QalPrGOepW8/hwwo8EUv5VpYc5HUbxnNU3EoBaSK adUWMKoq278aE12rzHjf4zgsUED1a/Tl6IfB+fYz25QhB6Ni5maSijgdXtmztA0jL7mJ xJRbxsncr11b5QssOj7r2Xx3mHGKIQfq8KJGYWlF49NThxjRRLnPaWKvg9DSG8mf1Dpi /x8A== X-Gm-Message-State: AOAM532HR9vGMZ+D9T4isGVIb68C7yauCiw3yiHPiHMagHu/La/wNE8J a4uyQBzQmmyAnF94Gcnfjk5FIaq5 X-Google-Smtp-Source: ABdhPJweLvR8ey11+azRBRiY5KYduv7yHDwZVwQkwd8ZfhEFjBZANMfz19xGX9ncAFov0SordjP9Tg== X-Received: by 2002:a17:906:8316:: with SMTP id j22mr13636814ejx.20.1596895743223; Sat, 08 Aug 2020 07:09:03 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g21sm7618991edm.65.2020.08.08.07.09.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Aug 2020 07:09:02 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Aug 2020 16:01:57 +0200 Message-Id: <20200808140202.586-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/6] avfilter/formats: Remove ff_make_formatu64_list() 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" It is unused since 8cbb055760c725d0fb99fb759caabb5f4e37e340 and it actually coincides with avfilter_make_format64_list(). Signed-off-by: Andreas Rheinhardt --- libavfilter/formats.c | 11 ----------- libavfilter/formats.h | 3 --- 2 files changed, 14 deletions(-) diff --git a/libavfilter/formats.c b/libavfilter/formats.c index de4315369d..bcc539bb38 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -289,17 +289,6 @@ AVFilterFormats *ff_make_format_list(const int *fmts) return formats; } -AVFilterChannelLayouts *ff_make_formatu64_list(const uint64_t *fmts) -{ - MAKE_FORMAT_LIST(AVFilterChannelLayouts, - channel_layouts, nb_channel_layouts); - if (count) - memcpy(formats->channel_layouts, fmts, - sizeof(*formats->channel_layouts) * count); - - return formats; -} - AVFilterChannelLayouts *avfilter_make_format64_list(const int64_t *fmts) { MAKE_FORMAT_LIST(AVFilterChannelLayouts, diff --git a/libavfilter/formats.h b/libavfilter/formats.h index cc588f30d8..708bee3ee8 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -141,9 +141,6 @@ AVFilterChannelLayouts *ff_all_channel_counts(void); av_warn_unused_result AVFilterChannelLayouts *avfilter_make_format64_list(const int64_t *fmts); -av_warn_unused_result -AVFilterChannelLayouts *ff_make_formatu64_list(const uint64_t *fmts); - /** * A helper for query_formats() which sets all links to the same list of channel From patchwork Sat Aug 8 14:01:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21540 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 BAF03449249 for ; Sat, 8 Aug 2020 17:09:28 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A274A68B7B9; Sat, 8 Aug 2020 17:09:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2ED6C68AD72 for ; Sat, 8 Aug 2020 17:09:22 +0300 (EEST) Received: by mail-ed1-f65.google.com with SMTP id c2so3252967edx.8 for ; Sat, 08 Aug 2020 07:09:22 -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=R9QOh2WdaX0Zaiu2zCPjRj0IyAjAjf9SEpZZcwCdqB0=; b=NWO3W47St3aeSQxfexFgfi0YoH+Cq0Fhr24ctYu9k4gWRfNUVMoNvmbaOrY1xRHdDm XM9JdXWAcSXNjyewskUR8W+mpfxb9WjpgOA7TuOAg1R02MnC1QckFCnp8lEEJ1Tpde1O nEwX42GHYMb2Lf8L/vA78ANXrEj/62FJ+u9aLrsnJivJcOcCe62QcmZU+HPRkVcZN/Z3 WAPHWOoMXdiNmWKnP50BPxuyxFsMcCqjHj6O8qXca7Jm8cdDZYdrHmDaH530bAd2N8Ga XfgjoyNY+b8WtEuREu2iHcnGOa+iB6w6hs2Ph+MjnrKhy8T2Jl+7PTaxrYy1CZIc7iyJ F+8Q== 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=R9QOh2WdaX0Zaiu2zCPjRj0IyAjAjf9SEpZZcwCdqB0=; b=nOqR1sNuR628h6QBhU0hrXO+TsFHFo5797gb1v8m1jW5x2U3Wly+vcxquai+FYYaYs f1smYVaTTBLMAqFnD9+mirWTcdn3NMpALt/58oL00TzXFBXEJQ2/SvLRtkEaQxClEris lnULk70emvwbaGidUILlJoAruKMP069iRbZ2SFmDPQMkaijlRvoQUtdjO/6tv9jDQ0Ql 406rEXCjGRIr9vagn7F9H1T8j17OLUU5BNgoi+cOn5RavbK48CELyoGP+LH+PsZ24Dc9 wddQS2kO+vzrKyXxH9zt3qzSnO6A27jOEG1R26uBdjROESytaj2+CetwiAmDE6uqp70D rFJg== X-Gm-Message-State: AOAM533phhIyVoPGIsBxfzVVRLSp0qZJQQamiRaR6Pqe8mDm4q6i6cGg cVzKg2GvY14gu3g6xyApcmOSEpxF X-Google-Smtp-Source: ABdhPJzEj2RzBpamy1WLDkNjiJdFTUyP/e9UA8n1HRy86Mi3/pMD8t1f0F/Pc1tjwI8x2Oy4x8++rA== X-Received: by 2002:a05:6402:785:: with SMTP id d5mr13711247edy.370.1596895761257; Sat, 08 Aug 2020 07:09:21 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g21sm7618991edm.65.2020.08.08.07.09.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Aug 2020 07:09:20 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Aug 2020 16:01:58 +0200 Message-Id: <20200808140202.586-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/6] avfilter/avf_showcqt: Mark arrays as static const 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" Signed-off-by: Andreas Rheinhardt --- libavfilter/avf_showcqt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavfilter/avf_showcqt.c b/libavfilter/avf_showcqt.c index cb0dca505f..990db3143b 100644 --- a/libavfilter/avf_showcqt.c +++ b/libavfilter/avf_showcqt.c @@ -1321,12 +1321,12 @@ static int query_formats(AVFilterContext *ctx) AVFilterChannelLayouts *layouts = NULL; AVFilterLink *inlink = ctx->inputs[0]; AVFilterLink *outlink = ctx->outputs[0]; - enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE }; - enum AVPixelFormat pix_fmts[] = { + static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE }; + static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE }; - int64_t channel_layouts[] = { AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_STEREO_DOWNMIX, -1 }; + static const int64_t channel_layouts[] = { AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_STEREO_DOWNMIX, -1 }; int ret; /* set input audio formats */ From patchwork Sat Aug 8 14:01:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21541 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 BA625449249 for ; Sat, 8 Aug 2020 17:09:32 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A30C968B933; Sat, 8 Aug 2020 17:09:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 26EB768B663 for ; Sat, 8 Aug 2020 17:09:26 +0300 (EEST) Received: by mail-ej1-f65.google.com with SMTP id d6so4963351ejr.5 for ; Sat, 08 Aug 2020 07:09:26 -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=tVSF+aEUNirnOCrQUgcAAhJGg1qFHLWzrqGLRwwXWWc=; b=B9kZBPciGI9sZ8LcKKdsvU8dKJE2mfEwWOVdzOHpuZbA472/Q1aUJ58UI8Unr3n2um 6j5HHfh4qn5Q0FNYqlNrQWg58Acp6WZluL1nI9LAJmWxTdrV+9FDW10XbIqHabCcQr48 CsTAOsbqG8Ouja1v/bPjSYUpSP+NhN3YtiNsE0ikLFvcRehfvZRYrYdp40Tl1emUkh+6 DUEMMi8k1JyQ++W7sTnF9h9PP5pO4eOyb0grK5eVRFURxBl3kl5W2blcfqZAx9ySHYFA O+CYhxQN65pS0yEKaUwtgTYVuFsRrZ10Xu1xIT/Rew9tOfvsQMGUPwb0zU+PcKp1t/+I Z3Jw== 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=tVSF+aEUNirnOCrQUgcAAhJGg1qFHLWzrqGLRwwXWWc=; b=p//ZRqnFgvsImdN9s3spYuyytR+9jp7teGAejDp62ebqic5BumlYq9pTwg5FtUH3A/ 2jJY2mJB0zbz7M//3L7c7ltxA4noyfHcvSFW6KB+Lq+x5wsFYQ+Z4kDV16ZaVZDhr4vH x85lRUgFn5ZKWPyskDLdDW4ebldo7hqvFuCQAofSv1TRIbuLmCq9W4Y4uBbykviVdtHU Gw6pFEGJFJIuS91bqw10u3NwwlahhBrYxt+J513SLyH64gfeeoQluS5B6YFEcXsSK2NE cwo8WdjS41Z3Ka2/1q9FkaHv1HWDmjD+iFRnL6BUtX16TYgxPsFNKdBnKOrH7Edaivn+ Ig8A== X-Gm-Message-State: AOAM530Ho4b1qmKjZcmen0E0hCwHz47L7r6H+MiAAWwZlXyDEfgXTa+N Dm20SohVQRO+XGC+etRkAwuO+yrs X-Google-Smtp-Source: ABdhPJyWoAZjWW2QBSfuu021ICe7y/aA6a+1g5mHxeDp2Gkju50wroXJkBx8AdFvZs3TvwIejInhAg== X-Received: by 2002:a17:906:9392:: with SMTP id l18mr13912479ejx.357.1596895765209; Sat, 08 Aug 2020 07:09:25 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g21sm7618991edm.65.2020.08.08.07.09.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Aug 2020 07:09:24 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Aug 2020 16:01:59 +0200 Message-Id: <20200808140202.586-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/6] avfilter/formats: Schedule avfilter_make_format64_list() for removal 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" Despite its name, this function is not part of the public API, as formats.h, the header containing its declaration, is a private header. The formats API was once public API, but that changed long ago (b74a1da49db5ebed51aceae6cacc2329288a92c1, the commit scheduling it to become private, is from 2012). That avfilter_make_format64_list() was forgotten is probably a result of the confusion resulting from the libav-ffmpeg split. Signed-off-by: Andreas Rheinhardt --- libavfilter/aeval.c | 2 +- libavfilter/af_aresample.c | 2 +- libavfilter/asrc_afirsrc.c | 2 +- libavfilter/asrc_anoisesrc.c | 2 +- libavfilter/asrc_anullsrc.c | 3 +-- libavfilter/asrc_hilbert.c | 2 +- libavfilter/asrc_sinc.c | 2 +- libavfilter/asrc_sine.c | 2 +- libavfilter/avf_showcqt.c | 2 +- libavfilter/formats.c | 9 ++++++++- libavfilter/formats.h | 6 +++++- libavfilter/src_movie.c | 2 +- 12 files changed, 23 insertions(+), 13 deletions(-) diff --git a/libavfilter/aeval.c b/libavfilter/aeval.c index 855dc0009d..c7a8cd6550 100644 --- a/libavfilter/aeval.c +++ b/libavfilter/aeval.c @@ -258,7 +258,7 @@ static int query_formats(AVFilterContext *ctx) if (ret < 0) return ret; - layouts = avfilter_make_format64_list(chlayouts); + layouts = ff_make_format64_list(chlayouts); if (!layouts) return AVERROR(ENOMEM); ret = ff_set_common_channel_layouts(ctx, layouts); diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c index fb10bd1c33..b7b1b5ba3c 100644 --- a/libavfilter/af_aresample.c +++ b/libavfilter/af_aresample.c @@ -126,7 +126,7 @@ static int query_formats(AVFilterContext *ctx) if(out_layout) { int64_t layout_list[] = { out_layout, -1 }; - out_layouts = avfilter_make_format64_list(layout_list); + out_layouts = ff_make_format64_list(layout_list); } else out_layouts = ff_all_channel_counts(); diff --git a/libavfilter/asrc_afirsrc.c b/libavfilter/asrc_afirsrc.c index b90ffad57f..d8ba8f6a54 100644 --- a/libavfilter/asrc_afirsrc.c +++ b/libavfilter/asrc_afirsrc.c @@ -145,7 +145,7 @@ static av_cold int query_formats(AVFilterContext *ctx) if (ret < 0) return ret; - layouts = avfilter_make_format64_list(chlayouts); + layouts = ff_make_format64_list(chlayouts); if (!layouts) return AVERROR(ENOMEM); ret = ff_set_common_channel_layouts(ctx, layouts); diff --git a/libavfilter/asrc_anoisesrc.c b/libavfilter/asrc_anoisesrc.c index 7aa878707d..40ee077001 100644 --- a/libavfilter/asrc_anoisesrc.c +++ b/libavfilter/asrc_anoisesrc.c @@ -101,7 +101,7 @@ static av_cold int query_formats(AVFilterContext *ctx) if (ret < 0) return ret; - layouts = avfilter_make_format64_list(chlayouts); + layouts = ff_make_format64_list(chlayouts); if (!layouts) return AVERROR(ENOMEM); ret = ff_set_common_channel_layouts(ctx, layouts); diff --git a/libavfilter/asrc_anullsrc.c b/libavfilter/asrc_anullsrc.c index 52db61685d..7093f08275 100644 --- a/libavfilter/asrc_anullsrc.c +++ b/libavfilter/asrc_anullsrc.c @@ -83,11 +83,10 @@ static int query_formats(AVFilterContext *ctx) int ret; if ((ret = ff_set_common_formats (ctx, ff_all_formats (AVMEDIA_TYPE_AUDIO))) < 0 || - (ret = ff_set_common_channel_layouts (ctx, avfilter_make_format64_list (chlayouts ))) < 0 || (ret = ff_set_common_samplerates (ctx, ff_make_format_list (sample_rates ))) < 0) return ret; - return 0; + return ff_set_common_channel_layouts(ctx, ff_make_format64_list(chlayouts)); } static int config_props(AVFilterLink *outlink) diff --git a/libavfilter/asrc_hilbert.c b/libavfilter/asrc_hilbert.c index a51c676c6f..640dfe46f9 100644 --- a/libavfilter/asrc_hilbert.c +++ b/libavfilter/asrc_hilbert.c @@ -113,7 +113,7 @@ static av_cold int query_formats(AVFilterContext *ctx) if (ret < 0) return ret; - layouts = avfilter_make_format64_list(chlayouts); + layouts = ff_make_format64_list(chlayouts); if (!layouts) return AVERROR(ENOMEM); ret = ff_set_common_channel_layouts(ctx, layouts); diff --git a/libavfilter/asrc_sinc.c b/libavfilter/asrc_sinc.c index 24aeab6e7b..c3ecb864d1 100644 --- a/libavfilter/asrc_sinc.c +++ b/libavfilter/asrc_sinc.c @@ -84,7 +84,7 @@ static int query_formats(AVFilterContext *ctx) if (ret < 0) return ret; - layouts = avfilter_make_format64_list(chlayouts); + layouts = ff_make_format64_list(chlayouts); if (!layouts) return AVERROR(ENOMEM); ret = ff_set_common_channel_layouts(ctx, layouts); diff --git a/libavfilter/asrc_sine.c b/libavfilter/asrc_sine.c index 3a87210b4b..6fe080efb6 100644 --- a/libavfilter/asrc_sine.c +++ b/libavfilter/asrc_sine.c @@ -194,7 +194,7 @@ static av_cold int query_formats(AVFilterContext *ctx) if (ret < 0) return ret; - layouts = avfilter_make_format64_list(chlayouts); + layouts = ff_make_format64_list(chlayouts); if (!layouts) return AVERROR(ENOMEM); ret = ff_set_common_channel_layouts(ctx, layouts); diff --git a/libavfilter/avf_showcqt.c b/libavfilter/avf_showcqt.c index 990db3143b..95efe72628 100644 --- a/libavfilter/avf_showcqt.c +++ b/libavfilter/avf_showcqt.c @@ -1334,7 +1334,7 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0) return ret; - layouts = avfilter_make_format64_list(channel_layouts); + layouts = ff_make_format64_list(channel_layouts); if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0) return ret; diff --git a/libavfilter/formats.c b/libavfilter/formats.c index bcc539bb38..48b27d0c53 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -289,7 +289,7 @@ AVFilterFormats *ff_make_format_list(const int *fmts) return formats; } -AVFilterChannelLayouts *avfilter_make_format64_list(const int64_t *fmts) +AVFilterChannelLayouts *ff_make_format64_list(const int64_t *fmts) { MAKE_FORMAT_LIST(AVFilterChannelLayouts, channel_layouts, nb_channel_layouts); @@ -300,6 +300,13 @@ AVFilterChannelLayouts *avfilter_make_format64_list(const int64_t *fmts) return formats; } +#if LIBAVFILTER_VERSION_MAJOR < 8 +AVFilterChannelLayouts *avfilter_make_format64_list(const int64_t *fmts) +{ + return ff_make_format64_list(fmts); +} +#endif + #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \ do { \ type *fmts; \ diff --git a/libavfilter/formats.h b/libavfilter/formats.h index 708bee3ee8..ffe7a12d53 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -20,6 +20,7 @@ #define AVFILTER_FORMATS_H #include "avfilter.h" +#include "version.h" /** * A list of supported formats for one end of a filter link. This is used @@ -139,8 +140,11 @@ av_warn_unused_result AVFilterChannelLayouts *ff_all_channel_counts(void); av_warn_unused_result -AVFilterChannelLayouts *avfilter_make_format64_list(const int64_t *fmts); +AVFilterChannelLayouts *ff_make_format64_list(const int64_t *fmts); +#if LIBAVFILTER_VERSION_MAJOR < 8 +AVFilterChannelLayouts *avfilter_make_format64_list(const int64_t *fmts); +#endif /** * A helper for query_formats() which sets all links to the same list of channel diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c index 476b8d3d96..64d82e9df1 100644 --- a/libavfilter/src_movie.c +++ b/libavfilter/src_movie.c @@ -376,7 +376,7 @@ static int movie_query_formats(AVFilterContext *ctx) if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_samplerates)) < 0) return ret; list64[0] = c->channel_layout; - if ((ret = ff_channel_layouts_ref(avfilter_make_format64_list(list64), + if ((ret = ff_channel_layouts_ref(ff_make_format64_list(list64), &outlink->in_channel_layouts)) < 0) return ret; break; From patchwork Sat Aug 8 14:02:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21542 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 1A0EF44927A for ; Sat, 8 Aug 2020 17:10:18 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F1D1768B914; Sat, 8 Aug 2020 17:10:17 +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 CF7C168B420 for ; Sat, 8 Aug 2020 17:10:11 +0300 (EEST) Received: by mail-ed1-f67.google.com with SMTP id l23so3247517edv.11 for ; Sat, 08 Aug 2020 07:10:11 -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=/U4JUCtVsWYeHNKzFi5gkVymt9aplf1PqULd/YUYmXg=; b=b0H8jzyKaDEdm50nDmflrSDTrF/xdsf6cPgFaXS3y0jxOnbFEIxJL0mP0NEZuVWiVO fAUuDn7beAx1fvV/P8Bd4cNOG51inDUE0d5Kw3pBEfXaL9K7l3ieh+vwBxMTuOD5vTfo NAS6z2FiJWEZExQZhX9KhgFLNutzMlvpKeZDQVv9+hdGNcTa783njY4SJd8JrpYfWQqG 3cyCS6TqmbRz9V40ctYmrGPc5K7OMemnScXxk2eKiMmSyTEc4OEaOTRCbjiKtBNIcn6a QdapG1QLmIX2zqRiI2wS1tAz5X283TFTb4A93k5v9x+MpaI8tGfuH3uAX+grmcmfTt9v tcGA== 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=/U4JUCtVsWYeHNKzFi5gkVymt9aplf1PqULd/YUYmXg=; b=cUtS7cokr15ir8/GyNy2STKZ8sF9cfLXEKSgeHOsKA8tw8lQPiqmEBHCq0E1b63SdO 7BjN6KsJ3p8ovIjlUMkacltjOdD17evOMH0cmRcEgK1sh5GQujm+9Q6pA0ntiqu03eNR Wkuk8H0lQVhu24LY/TKLnk9DP1YRiBXbr10LxDq8Ztoy+14leAPp84EajK20fB0yV48B 1U6JfA3kzPDiR2Q9j+bkEYgBhVfdgnDMGE7tWRp1P2Nm9RLxmT3RC+ne5K0D9Dn4sC42 0Xpe7pLXJEiXIkvAuuo1bCM55O09gx/67QmDsfYdy3JA08TIqUQ2I8SEf1n5cZ8jzfme VsJg== X-Gm-Message-State: AOAM532Z+PwwDk1BpaXoX7XLAL8hl2l4knNVzTwxsdUGVtZw92o1C5U+ fmNCDcANNToAmnVQTiq6aqUUAdQ8 X-Google-Smtp-Source: ABdhPJxRFMK8fa/Wv7+AnU4umM9or9evgyxOQ+cDn5zOO7k5bDbEgb4jJGzCtiU6/dVeyknUgkQ5yQ== X-Received: by 2002:a05:6402:3193:: with SMTP id di19mr13698979edb.224.1596895810801; Sat, 08 Aug 2020 07:10:10 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g21sm7618991edm.65.2020.08.08.07.10.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Aug 2020 07:10:10 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Aug 2020 16:02:01 +0200 Message-Id: <20200808140202.586-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/6] avfilter/formats: Leave lists' ownership unchanged upon merge 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" ff_merge_formats(), ff_merge_samplerates() and ff_merge_channel_layouts() share common semantics: If merging succeeds, a non-NULL pointer is returned and both input lists (of type AVFilterFormats resp. AVFilterChannelLayouts) are to be treated as if they had been freed; the owners of the input parameters (if any) become owners of the returned list. If merging does not succeed, NULL is returned and both input lists are supposed to be unchanged. The problem is that the functions did not abide by these semantics: In case of reallocation failure, it is possible for these functions to return NULL after having already freed one of the two input list. This happens because sometimes the refs-array of the destined output gets reallocated twice to its final size and if the second of these reallocations fails, the first of the two inputs has already been freed and its refs updated to point to the destined output which in this case will be freed immediately so that all of the already updated pointers are now dangling. This leads to use-after-frees and memory corruptions lateron (when these owners get cleaned up, the lists they own get unreferenced). Should the input lists don't have owners at all, the caller (namely can_merge_formats() in avfiltergraph.c) thinks that both the input lists are unchanged and need to be freed, leading to a double free. The solution to this is simple: Don't reallocate twice; do it just once. This also saves a reallocation. This commit fixes the issue behind Coverity issue #1452636. It might also make Coverity realize that the issue has been fixed. Signed-off-by: Andreas Rheinhardt --- This is not the only thing wrong with the formats API. Will soon send more; those who can't wait can already take a look at https://github.com/mkver/FFmpeg/commits/avfilter The most important of these patches is https://github.com/mkver/FFmpeg/commit/a151b88f395387c4bb85fbf14c042e2cd3f677ed libavfilter/formats.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 48b27d0c53..ae44006dfe 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -31,19 +31,14 @@ #define KNOWN(l) (!FF_LAYOUT2COUNT(l)) /* for readability */ + /** * Add all refs from a to ret and destroy a. + * ret->refs must have enough spare room left for this. */ -#define MERGE_REF(ret, a, fmts, type, fail) \ +#define MERGE_REF_NO_ALLOC(ret, a, fmts) \ do { \ - type ***tmp; \ int i; \ - \ - if (!(tmp = av_realloc_array(ret->refs, ret->refcount + a->refcount, \ - sizeof(*tmp)))) \ - goto fail; \ - ret->refs = tmp; \ - \ for (i = 0; i < a->refcount; i ++) { \ ret->refs[ret->refcount] = a->refs[i]; \ *ret->refs[ret->refcount++] = ret; \ @@ -54,6 +49,17 @@ do { \ av_freep(&a); \ } while (0) +#define MERGE_REF(ret, a, fmts, type, fail) \ +do { \ + type ***tmp; \ + \ + if (!(tmp = av_realloc_array(ret->refs, ret->refcount + a->refcount, \ + sizeof(*tmp)))) \ + goto fail; \ + ret->refs = tmp; \ + MERGE_REF_NO_ALLOC(ret, a, fmts); \ +} while (0) + /** * Add all formats common for a and b to ret, copy the refs and destroy * a and b. @@ -61,6 +67,7 @@ do { \ #define MERGE_FORMATS(ret, a, b, fmts, nb, type, fail) \ do { \ int i, j, k = 0, count = FFMIN(a->nb, b->nb); \ + type ***tmp; \ \ if (!(ret = av_mallocz(sizeof(*ret)))) \ goto fail; \ @@ -85,8 +92,13 @@ do { if (!ret->nb) \ goto fail; \ \ - MERGE_REF(ret, a, fmts, type, fail); \ - MERGE_REF(ret, b, fmts, type, fail); \ + tmp = av_realloc_array(NULL, a->refcount + b->refcount, sizeof(*tmp)); \ + if (!tmp) \ + goto fail; \ + ret->refs = tmp; \ + \ + MERGE_REF_NO_ALLOC(ret, a, fmts); \ + MERGE_REF_NO_ALLOC(ret, b, fmts); \ } while (0) AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b, @@ -238,8 +250,13 @@ AVFilterChannelLayouts *ff_merge_channel_layouts(AVFilterChannelLayouts *a, ret->nb_channel_layouts = ret_nb; if (!ret->nb_channel_layouts) goto fail; - MERGE_REF(ret, a, channel_layouts, AVFilterChannelLayouts, fail); - MERGE_REF(ret, b, channel_layouts, AVFilterChannelLayouts, fail); + + ret->refs = av_realloc_array(NULL, a->refcount + b->refcount, + sizeof(*ret->refs)); + if (!ret->refs) + goto fail; + MERGE_REF_NO_ALLOC(ret, a, channel_layouts); + MERGE_REF_NO_ALLOC(ret, b, channel_layouts); return ret; fail: From patchwork Sat Aug 8 14:02: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: 21543 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 69C5F44927A for ; Sat, 8 Aug 2020 17:10:22 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 40D1B68B941; Sat, 8 Aug 2020 17:10:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8353E68B919 for ; Sat, 8 Aug 2020 17:10:15 +0300 (EEST) Received: by mail-ej1-f66.google.com with SMTP id kq25so4966884ejb.3 for ; Sat, 08 Aug 2020 07:10:15 -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=F7B43d+Th2EvqAVsmFIpaY9qpDuzm2LmyZ5pjvAcQ6U=; b=hbEmifu5sNeh77Y4ygsCDN3vwLLjbvlqJvzjuFI0doOlIHRw8FtlCdghRJYJ4EC53Y QHZRA42RS+f6KELgYHHX1Vd2qEKk56JoZkB1Ibp/ZaOi6OQzGh5OShZ5pggVIecb4u4e Bj1U6PPOi0oRiBtZlusOTSDC/WcuyH24ms7NTkKBMYEbnLqfHBxaQUHw5xZh8xsg4b3L MsjNCT4rq9qeFhkSAVCwBYyG/w43ARv89unFOGnT+ADanSSGrhB1DoFcb18aOgseu1Wb lWiL8T0H7KdRlQiMPqouEpfnfQqTwgO2jfdMPI+r3EBpewFZvJxJvNjEsiYryj0sWhof U34Q== 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=F7B43d+Th2EvqAVsmFIpaY9qpDuzm2LmyZ5pjvAcQ6U=; b=olcIJGduSdO1OCZUttNjxEJStKd+rjnVxRjF8u8oDuZg9lKqk9FO+4QzPkpd3ZzgAB kxQaHrQBBsxPV9SOuJBhFYZ1JqLiVleaOei26XnJhSrFfBbU89tm2mW0MRCXFZ+Espn9 fvTTaugd4lZvwWU/QQ4Praly/hL15sUr8jt0NB8S6O83J6Mf0m9sDCqvGS/TnLzX/APZ lbfMRmmqGugj3GAxODaRTJVAiFR1qF+FIskWS+4LXi6QwCdASwZPERLAADLj5PZClWL0 d35A7BcohVKGYi3KO/0ZT9VSgeaW1hVDGUGK93+P5EIwdngLcruLioSSGm9AdYwPxQVW nz2g== X-Gm-Message-State: AOAM530MZpAB1mIomHrlaO1V9+nw9zHEKBz6WvS8UE3sII32+D6pgM+h S5bWuhzpXdEQRU+1LnuOBElgxp6K X-Google-Smtp-Source: ABdhPJzTdBmOuc6Albbof5NcQcv2vLjD6DV2w+pt2n9WD8TJjBw5G02418kWw1gYGVUVJH2fbGC/ZA== X-Received: by 2002:a17:906:7787:: with SMTP id s7mr14831392ejm.533.1596895814689; Sat, 08 Aug 2020 07:10:14 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g21sm7618991edm.65.2020.08.08.07.10.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Aug 2020 07:10:14 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Aug 2020 16:02:02 +0200 Message-Id: <20200808140202.586-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/6] avfilter/formats: Simplify cleanup for ff_merge_* functions 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 the output's refs-array is only allocated once, it is NULL in any error case and therefore needn't be freed at all. Furthermore, it is unnecessary to av_freep(&ptr) when ptr == NULL. Signed-off-by: Andreas Rheinhardt --- libavfilter/formats.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libavfilter/formats.c b/libavfilter/formats.c index ae44006dfe..e452fd0408 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -141,10 +141,9 @@ AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b, return ret; fail: if (ret) { - av_freep(&ret->refs); av_freep(&ret->formats); + av_freep(&ret); } - av_freep(&ret); return NULL; } @@ -168,10 +167,9 @@ AVFilterFormats *ff_merge_samplerates(AVFilterFormats *a, return ret; fail: if (ret) { - av_freep(&ret->refs); av_freep(&ret->formats); + av_freep(&ret); } - av_freep(&ret); return NULL; } @@ -261,10 +259,9 @@ AVFilterChannelLayouts *ff_merge_channel_layouts(AVFilterChannelLayouts *a, fail: if (ret) { - av_freep(&ret->refs); av_freep(&ret->channel_layouts); + av_freep(&ret); } - av_freep(&ret); return NULL; } From patchwork Sat Aug 8 14:02:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21544 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 8113344927A for ; Sat, 8 Aug 2020 17:10:23 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 631E168B970; Sat, 8 Aug 2020 17:10:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 48FA068B96E for ; Sat, 8 Aug 2020 17:10:17 +0300 (EEST) Received: by mail-ed1-f65.google.com with SMTP id q4so3240768edv.13 for ; Sat, 08 Aug 2020 07:10:17 -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=yiOLuoMh0HI5/n3GDm+wtBtKjtkcoEsiKdvOCQTVkG8=; b=QGqC5y3lUXjqxA+BDzVewxKpsuqAx5KN4QHf8clJM0OjjtWRD+C1GeKe+txtZzePTE +IbGhg/maZMt/qitIRmgiwuNmIBRi50Zhv1EBpxKTfPMQDn335IYpIsYb9O1FYQ4hMnz I4hNSosjVNempSCEFnsWwgNyWxOyJ8MYDc+ipJXadoWeKHSYHyuc28ixYxUbzKW8KVcr 5bMOgEh63iOZKCDVLwhaFEa+QvRpNvc7sb1gYGFFQwIcx0Y3jUpBHhU7e5UOva0Et8qV tPPztC5Le5Ie2V5drO5QpqgEFIRD25QSwPkgU8ZGbsJEsksYQSm6o8I5sbmaAogwVkhM WD/w== 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=yiOLuoMh0HI5/n3GDm+wtBtKjtkcoEsiKdvOCQTVkG8=; b=QP8bbuVupj4J6eyN/QqczrUTNFeZApZ8Qeg1WxnNwnO8ezQNsaBOIxif75AbW1lnDF sYLjO0Vh8Gn8w/P3QME4UG3jHDN/FzOuwveOSxfuxIzPs1KBQWUtFF9cSufpG9cxnduo GXv2ZaCGcbPLt4rZprpxgal0pHwimoHN0xW5XuypWZr13GnttDXj3p56ichSSIwc32za aS7+MAyyGly4cdPPRm9ay2DSfr4RlZWWzq2GMNgb6MVfxoXtiuu5qlhLSeHAzCbr7OMd qEElNwb3C6evasiYMbFnWvV9B+NKJlJ6MasyG9sLweKlOn232QwnIQbgiPqsWkQg3zm2 +NLw== X-Gm-Message-State: AOAM532LdIIe4ViJ9xWN5zMQcFBxN9gpPXz4U7WpSJE5gTqJB8tmddJa C0Lnm75vYcZYD9QfI/BY9fbbNTbe X-Google-Smtp-Source: ABdhPJymc0DjkofTOm2Hh/MNab5JwXBu6FQqRyeX4VwqNatygkIiebkD26Jd/7w59YNrA23g+tSNlA== X-Received: by 2002:a50:fc82:: with SMTP id f2mr13259237edq.53.1596895816465; Sat, 08 Aug 2020 07:10:16 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g21sm7618991edm.65.2020.08.08.07.10.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Aug 2020 07:10:15 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Aug 2020 16:02:03 +0200 Message-Id: <20200808140202.586-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/6] Revert "lavfi/avfiltergraph: add check before free the format" 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" This reverts commit f156f4ab2317f22bfef33c7eaead0d5d5f162903. The checks added by said commit are nonsense because they did not help in case ff_merge_samplerates() or ff_merge_formats() returned NULL while freeing one of its arguments: Said freeing does not change the local variables of can_merge_formats(). Signed-off-by: Andreas Rheinhardt --- libavfilter/avfiltergraph.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 2fe4f0b0f9..a149f8fb6d 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -419,10 +419,8 @@ static int can_merge_formats(AVFilterFormats *a_arg, av_freep(&ret); return 1; } else { - if (a) - av_freep(&a->formats); - if (b) - av_freep(&b->formats); + av_freep(&a->formats); + av_freep(&b->formats); av_freep(&a); av_freep(&b); return 0; From patchwork Sun Aug 9 15:57:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21550 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 7E5B944B9EE for ; Sun, 9 Aug 2020 18:58:08 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5B4C868A3F8; Sun, 9 Aug 2020 18:58:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F3D7689C95 for ; Sun, 9 Aug 2020 18:58:02 +0300 (EEST) Received: by mail-ej1-f65.google.com with SMTP id c16so6973251ejx.12 for ; Sun, 09 Aug 2020 08:58:02 -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=WUGcujyJbr3LMjp7wm9763W/6MsEkAIrKNhf3/mXqfM=; b=CdgEgo+NxxdLDgPDJkxC2x4h1FSN+swFO7+LlGOesGeoXLUyvxCFARATv1vVQTSnfl j7X6Ut91TqZw85uzXDeC1AdI0e/uvZrM9p3+QeZx+GXzYZIcuZGQ0TxpV89cdwCWHgSk PsSY0mYvJ94i9DMHyBQju9yXqJ7kN3nX7MGORTykQ5l/jtnZAa/QvMdr/teDEpoz/hnH jQ44DcC1i4SJHO8T0ncuNVGsQ1hdEcIMIpbDfrrtbtlmLTKhhFPzLG7F+P7y/99QheE4 dmDdZshoVCsWZTzZR/xGlYOg+APa0OJFsRf7oaz/tv7lLyiCytX3E7y5YITUNnD2uvQe 4ldw== 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=WUGcujyJbr3LMjp7wm9763W/6MsEkAIrKNhf3/mXqfM=; b=dOKeCGLzm4kX6DJnlEDpUm086tL1KuNc5ntKKJuh7CT22oc+SywRoIeZRGX1g6Q7s4 zvEL38LGvU9nwWxEAVwZlC+CTtoy7cuojQg/KPuaBpBpW8EZT7KBCVy1pW6EwLtY58F+ nD6iWfZ7eNfAvMJaxD79honjL9FyGZOhQcH+hua/SNh/OXHp2v6W4KW4qVjZnTnZYoJ/ 0XRDmokMhRcLO97LzAGXxl96jIDXo+6dx9YLNaeFHhiUkzuov1V3z/cCk8iqGQVSWpGG pvadXNIhcay+9/XGbpnEaIqwz7klyCqcSujMvmF5jZF34S6Zct5qPFTdPPS7LjLmqWq2 Jiww== X-Gm-Message-State: AOAM531ezaFqhXyh64H4z3O6agFdMUVf1Q+vzkbUAWVhQfO4PCKHKo1q L3njDmsQCS19m11d616s4ItjUr+K X-Google-Smtp-Source: ABdhPJy3luBFTEHA9qmnr5v1SCaQmTdaS3rDXFeV0KrDDNRM6wuJaDb8YQT0ty/Bakxs9tsHUCeK2g== X-Received: by 2002:a17:906:600f:: with SMTP id o15mr18536959ejj.41.1596988681039; Sun, 09 Aug 2020 08:58:01 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:00 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:34 +0200 Message-Id: <20200809155748.30092-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/21] avfilter/af_afir: Fix leak of AVFilterChannelLayout in case of 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" If an error happens between the allocation of an AVFilterChannelLayout and its usage (which involves attaching said object to a more permanent object), the channel layout array leaks. This can simply be fixed by making sure that nothing is between the allocation and the aforementioned usage. Fixes Coverity issue #1250334. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_afir.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c index 5ba880f10b..6cbc7a00a1 100644 --- a/libavfilter/af_afir.c +++ b/libavfilter/af_afir.c @@ -742,14 +742,14 @@ static int query_formats(AVFilterContext *ctx) } else { AVFilterChannelLayouts *mono = NULL; - ret = ff_add_channel_layout(&mono, AV_CH_LAYOUT_MONO); - if (ret) - return ret; - if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->out_channel_layouts)) < 0) return ret; if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts)) < 0) return ret; + + ret = ff_add_channel_layout(&mono, AV_CH_LAYOUT_MONO); + if (ret) + return ret; for (int i = 1; i < ctx->nb_inputs; i++) { if ((ret = ff_channel_layouts_ref(mono, &ctx->inputs[i]->out_channel_layouts)) < 0) return ret; From patchwork Sun Aug 9 15:57:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21551 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 70BF644B9EE for ; Sun, 9 Aug 2020 18:58:19 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 51EC368A91A; Sun, 9 Aug 2020 18:58:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D57DA689C95 for ; Sun, 9 Aug 2020 18:58:12 +0300 (EEST) Received: by mail-ej1-f68.google.com with SMTP id f24so6997744ejx.6 for ; Sun, 09 Aug 2020 08:58:12 -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=ZLIv7zPhg50wNQnaBYw1cNsRAOqihLzXFfTRd+Ab5vg=; b=Rq805q6DXixIkD/UQLHmoPJ8wZH3IgglpiDALNd61JBZOUCuAFo20FPRpSg2TgZGaA +JtuG9xNg696By2ceXudvQgGvuk5o5jt1c5gNSB1VL1QuSx1MbqK05zw57PaJOMCsGGr ekjdQKsXB76TwZZTocUTpjjO32FtfcqKfQWUAVXQgEg3BUnv6bVsEVbnHD3DSVL3R8CD vuPHb19himY+avc7XkjXOYkAXtYO/x22un1Mctc1WT8YJEE2VlBGTwqoHfxR8mRn0/1f tsAZxT8HMdcRJXnuF29XFqMg4xtzM+ZrdlU6m31+Wi6Ay22BOeuESLkVudmpp0nYuz// hjgg== 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=ZLIv7zPhg50wNQnaBYw1cNsRAOqihLzXFfTRd+Ab5vg=; b=POv9z30wdq/cqq77mydXxlaXJiknuZbXnD+TERsqcuODVwTT9I2GWyc8L84pVMT8G/ vFQDSsiwS5LqguOu+FM1jDql+haz2/GMS62PWGgPUaVqodybnFPlXgh/GYmJwc1bx8Rk Eygeyz0VK5xUpvWBGtYKL97cD9f7sXr8+SbMYII/eywigL2849E4HXAYFVQhClL4Hkyb RHwXEW+IWdD4jSseSZYarz3WphwH4SfhLWk09z5Zwu2QVcU/iDkEL3A42drhZp5y0ZJt eO4jZHyfSUPNi3rTzJ0ec3e2Hcj7xAKJw0BeVIwfpcv6tj2naCBvsTbjfHW1GyI/q7Ma dCvQ== X-Gm-Message-State: AOAM531MVafJ7ucaCYLwTLkKnw3fUbS07YaML/OXGNMTI86eJubKx0tF mucTirtUcKtSh8x3BRvLwvSdw97f X-Google-Smtp-Source: ABdhPJzK2EgpUaSgbF0GXlFJi+Yt3AnEj8DVWO00XTPFA8DS1VBol9T3x+QOHaD6hl6K24rdBWhk5Q== X-Received: by 2002:a17:906:7790:: with SMTP id s16mr19249322ejm.254.1596988692119; Sun, 09 Aug 2020 08:58:12 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:11 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:35 +0200 Message-Id: <20200809155748.30092-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/21] avfilter/vf_paletteuse: Fix leaks of AVFilterFormats on 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" The paletteuse's query_formats function allocated three AVFilterFormats before storing them permanently. If allocating one of them failed, the three AVFilterFormats structures would be freed with av_freep() which does not free separately allocated subelements (namely the formats array) which leak. Furthermore, if storing one of the first two fails, the function simply returns and the ones not yet stored leak. These leaks have been fixed by only creating a new AVFilterFormats after the last one has already been permanently stored. Furthermore, it is enough to check whether the elements have been properly stored as ff_formats_ref() by design returns AVERROR(ENOMEM) if it is provided a NULL AVFilterFormats *. Fixes Coverity issues #1270818 and #1270819. Signed-off-by: Andreas Rheinhardt --- libavfilter/vf_paletteuse.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/libavfilter/vf_paletteuse.c b/libavfilter/vf_paletteuse.c index b32ff817d0..80e2ba583a 100644 --- a/libavfilter/vf_paletteuse.c +++ b/libavfilter/vf_paletteuse.c @@ -142,18 +142,12 @@ static int query_formats(AVFilterContext *ctx) static const enum AVPixelFormat inpal_fmts[] = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE}; static const enum AVPixelFormat out_fmts[] = {AV_PIX_FMT_PAL8, AV_PIX_FMT_NONE}; int ret; - AVFilterFormats *in = ff_make_format_list(in_fmts); - AVFilterFormats *inpal = ff_make_format_list(inpal_fmts); - AVFilterFormats *out = ff_make_format_list(out_fmts); - if (!in || !inpal || !out) { - av_freep(&in); - av_freep(&inpal); - av_freep(&out); - return AVERROR(ENOMEM); - } - if ((ret = ff_formats_ref(in , &ctx->inputs[0]->out_formats)) < 0 || - (ret = ff_formats_ref(inpal, &ctx->inputs[1]->out_formats)) < 0 || - (ret = ff_formats_ref(out , &ctx->outputs[0]->in_formats)) < 0) + if ((ret = ff_formats_ref(ff_make_format_list(in_fmts), + &ctx->inputs[0]->out_formats)) < 0 || + (ret = ff_formats_ref(ff_make_format_list(inpal_fmts), + &ctx->inputs[1]->out_formats)) < 0 || + (ret = ff_formats_ref(ff_make_format_list(out_fmts), + &ctx->outputs[0]->in_formats)) < 0) return ret; return 0; } From patchwork Sun Aug 9 15:57:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21552 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 67C2B44B9EE for ; Sun, 9 Aug 2020 18:58:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4DA6D68AA12; Sun, 9 Aug 2020 18:58:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E2A9A68A8E9 for ; Sun, 9 Aug 2020 18:58:22 +0300 (EEST) Received: by mail-ej1-f66.google.com with SMTP id c16so6973782ejx.12 for ; Sun, 09 Aug 2020 08:58:22 -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=SqfvqSDIZhzE+hoqAoF0a/+nQksMov8P6L6P0EWVVts=; b=hi6/Lg8+svrmzTsCCzIR018/GkVONDjnZ0atZKN14FR4LH7R7wZCUuaPUKFBzHH39P MZDzXxtQtqmwf+tGPvngPmkjeYo+HlOFBEQdNi3yX7n8JFGxmjhEicHAobg5gNhUJwpq afA7RwluKlUepXeHKKidXIBDtw5auhaDFij2bwD6L5FS1GZedImn/+sAGMkqqJn+wfwh n3GDFGnC+35e4mDYYlpy1J27agqlK54E4YaxXfiAnEfEpafxO6Dwa35GAfiR/aZRPKYj dFQqL/LlkIu/tD+ZWaQu8laXZ+4SWiMkODS0XbybtlnUXEEzaoo0nlpZHJcoVPUcalXF OpIw== 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=SqfvqSDIZhzE+hoqAoF0a/+nQksMov8P6L6P0EWVVts=; b=hISIaSZGpAnOrb7EEVOInjJaL9KD60m4lwVBPNoevhSpdbp8WvVq/X4nDd1VZIh9qr yoNgCzy2KlWwn6KVqAlMNM+BmWsK6F5AX/5dKbHCikpcrcTUZVkAD1ZURwrNOhYQ1x0N gfbImjuB7aELg4vWtjWIJ9AaCHiKztfcwpCdf6mPykmg+dmJP6vvlcDlDgvrWSLu4Mbf lOGZNoyDuG/ybt4QaoUMBGnWtg5E05Fc20M4Ch9tMaqLJUuAw6nlMhdcKFLR8oowGaWT xTG7NCV5WUMcX0XmPGyMgZgilxCoAbo5hKemQwwax060YTd3xdnGkuCxq8Utnbpt25dV gy9w== X-Gm-Message-State: AOAM530L87lDI2b/ZRPETxRaAFnOdZwEDEwqo/l33GZfvlcf4K4MeXIq OsN1uqsrSyd7/ZNoWKVYcJVFsWEE X-Google-Smtp-Source: ABdhPJwXRB4B+sEU9VFeReolAZgW2kOuyNhLBUnDa0h7JB7qaTO9GtF77PFIgf6eHvjbWOobWiaHWQ== X-Received: by 2002:a17:906:1cd3:: with SMTP id i19mr3160130ejh.552.1596988702044; Sun, 09 Aug 2020 08:58:22 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:21 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:36 +0200 Message-Id: <20200809155748.30092-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/21] avfilter/vf_vpp_qsv: Fix leak of AVFilterFormats on 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" The vpp_qsv's query_formats function allocated two AVFilterFormats, before storing them permanently. If storing the first of them fails, the function simply returns and the second leaks. This has been fixed by only allocating the second AVFilterFormats structure after the first one has been successfully stored. Fixes Coverity issue #1422231. Signed-off-by: Andreas Rheinhardt --- libavfilter/vf_vpp_qsv.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c index 3194295f5f..12023af2d7 100644 --- a/libavfilter/vf_vpp_qsv.c +++ b/libavfilter/vf_vpp_qsv.c @@ -489,7 +489,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) static int query_formats(AVFilterContext *ctx) { int ret; - AVFilterFormats *in_fmts, *out_fmts; static const enum AVPixelFormat in_pix_fmts[] = { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NV12, @@ -505,16 +504,12 @@ static int query_formats(AVFilterContext *ctx) AV_PIX_FMT_NONE }; - in_fmts = ff_make_format_list(in_pix_fmts); - out_fmts = ff_make_format_list(out_pix_fmts); - ret = ff_formats_ref(in_fmts, &ctx->inputs[0]->out_formats); + ret = ff_formats_ref(ff_make_format_list(in_pix_fmts), + &ctx->inputs[0]->out_formats); if (ret < 0) return ret; - ret = ff_formats_ref(out_fmts, &ctx->outputs[0]->in_formats); - if (ret < 0) - return ret; - - return 0; + return ff_formats_ref(ff_make_format_list(out_pix_fmts), + &ctx->outputs[0]->in_formats); } static av_cold void vpp_uninit(AVFilterContext *ctx) From patchwork Sun Aug 9 15:57:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21553 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 9F38444B9EE for ; Sun, 9 Aug 2020 18:58:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7F38A68AAD8; Sun, 9 Aug 2020 18:58:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E430668A922 for ; Sun, 9 Aug 2020 18:58:23 +0300 (EEST) Received: by mail-ej1-f65.google.com with SMTP id a26so7010749ejc.2 for ; Sun, 09 Aug 2020 08:58:23 -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=Yc6A6SAIGynWLK4HmyDdKOWBgiHv/Db0hWLXsz4DzXQ=; b=qMqNvh95dajkJnWBekH1BndL0QvrgOIy6bdDSR3fmxxiFFK0tg6unXMbDC0aLJ6Wbl ofuebmJIGHLJ1yQzjAr/SDsAQiwjexNvDB5v+tEaRZv/hUUQl6Np1aqcjzJLOhTsRspA mSYF9YeqF2fbmrYTCNq3tiaCwm7qSD3oVrAiBoOcupStqFfqd4tWc7+mgCWh5PK/Dks8 IQrmTnE0z5ZPPRtY+xkhBZ/+pY8P443+YPci1QrltiFtFkyA+EU4iz3wKLIviocJY1NT n55D3du4FPbUWj1UZpzpRw3gFexgVS1R0op4TboA8Rmw3ELwyUVQH7XDOs4QZ6DtLCJQ 0IqA== 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=Yc6A6SAIGynWLK4HmyDdKOWBgiHv/Db0hWLXsz4DzXQ=; b=Hbtyh2l+pMUWfX7yOOIomi2J4E1hbTDQOgQxS+u9vp335CdOcrfecSSAuynnUVcOjw yCBhEjyH7bzfVLpcFEJiillL/uHfGg+EnGLguAAg+4CD6tIkMjjze1uTs1iuwZUo+p6y S+sTne8lqlTU9m8yTZ3LKb+f9Ed2oNvkLNJ0vuh1NwLi7aZ8tbJmsAveQbMOygZp6FUm ZY9Ye9lu/EhTHQPtTzdfEyvZZ6nV57+TeJqx20mbRN9953XQA0dAZzZkUZM/X5Fysfe/ NCI/dNhmz+CEjUY6rAjiUzKT8ooZrJoEg18xS+fqf8uZ74EIwWfDM0m/hFGmKz7CQBKc MFwQ== X-Gm-Message-State: AOAM530r0oPcCHAZjQ230lie27JxG0z5dIgwQXDW9u5IARjyDwfQ1lRT hN4eSfUV7Hq6QCGsnpjqRZpogxMx X-Google-Smtp-Source: ABdhPJxFnX7LxihRfgqVTxshQSU2c32WstifyVelHqv1QVQDxEOoEcN5xmvGYxkflQqEP29uMHOUbQ== X-Received: by 2002:a17:906:386:: with SMTP id b6mr17898051eja.538.1596988703125; Sun, 09 Aug 2020 08:58:23 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:22 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:37 +0200 Message-Id: <20200809155748.30092-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/21] avfilter/af_amix: Don't needlessly reallocate table 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" Replace using ff_add_format() repeatedly by a single call to ff_make_format_list(). (Right now this also fixes a memleak: If the first ff_add_format() succeeds and a subsequent call fails, the list leaks.) Signed-off-by: Andreas Rheinhardt --- libavfilter/af_amix.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c index 0826fc118c..6a4ef8d944 100644 --- a/libavfilter/af_amix.c +++ b/libavfilter/af_amix.c @@ -588,7 +588,11 @@ static av_cold void uninit(AVFilterContext *ctx) static int query_formats(AVFilterContext *ctx) { - AVFilterFormats *formats = NULL; + static const enum AVSampleFormat sample_fmts[] = { + AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP, + AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBLP, + AV_SAMPLE_FMT_NONE + }; AVFilterChannelLayouts *layouts; int ret; @@ -598,11 +602,7 @@ static int query_formats(AVFilterContext *ctx) goto fail; } - if ((ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLT )) < 0 || - (ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLTP)) < 0 || - (ret = ff_add_format(&formats, AV_SAMPLE_FMT_DBL )) < 0 || - (ret = ff_add_format(&formats, AV_SAMPLE_FMT_DBLP)) < 0 || - (ret = ff_set_common_formats (ctx, formats)) < 0 || + if ((ret = ff_set_common_formats(ctx, ff_make_format_list(sample_fmts))) < 0 || (ret = ff_set_common_channel_layouts(ctx, layouts)) < 0 || (ret = ff_set_common_samplerates(ctx, ff_all_samplerates())) < 0) goto fail; From patchwork Sun Aug 9 15:57:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21554 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 131C044B9EE for ; Sun, 9 Aug 2020 18:58:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EB83368A8E9; Sun, 9 Aug 2020 18:58:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C751468A8E9 for ; Sun, 9 Aug 2020 18:58:25 +0300 (EEST) Received: by mail-ed1-f66.google.com with SMTP id v22so4686427edy.0 for ; Sun, 09 Aug 2020 08:58:25 -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=3JyuBEp5mIQdAE8lEjqVfWGHGxal/bodzhT4CP49KLQ=; b=pUjtzioPscJ4Cr+ev+uDx/xwz70Qa+abkiyXY44ISCrskp0PNBjq6JUNSUiD4Efxap VNAL3GSxoBTUlRObLEVhvSm0CqFo0lE3LzGb7M0n2fTmrbD+QCzE+jTub5tsUlJ21ZNX tj3osXpuf+NX8MTx39EJfjeoGMhqQqqXrkyl744f8lBd2kOxhdgtmaulUX1Gtb9ORsm8 i1jqziq3Utmm7QkqwQAtg0fr58uFSvNeI0W8vKQjEPGPFZ0mdCCpuVozsw+OPzGHgSEz HPpuLEeof23AHamLB+WXViuskW4Y/PtT7rWPDC0tukI2N3ooywp9+2UNbRn+dY2wvBMz JY6A== 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=3JyuBEp5mIQdAE8lEjqVfWGHGxal/bodzhT4CP49KLQ=; b=cfHkCejst2OmcfacjCHXNDE41c8tqJhHjROTK0JWg0TUZXKnmZ7UGuu3rkWVH5an8S 9mydRYN9gnRC5xqBT+wLe1w3wemjSZKDJQlZDXjsv7mxbPY5p5yWR3o3bZpZqEPXbiqy 1GclcBx7v4GcQXJHsNOeuRItaVLlYu3J0UfQHo7xH/Z6oTzaw1NqkVDs1RKu0A1Zmoxp x6pn2+rWWQyjw5b+0Leb0Ximnxiiw3KJ2HlLNXyXIGU8lzdADNPrmUMMkCMPkYXIjiZs ySc+vCYq8ozBgC+yJwpucSZ604+HrUqBXZobs6znVfxb59DRl0HcHJ80CS5QAiCaTnfC xVFg== X-Gm-Message-State: AOAM53005modGZaob4Tzzd6g3UMhNojB1gaOkh6LAgTJGgDIJ1zFpp/Z P/GZr5Ya6DH1UuADTKfwtZTLHv0P X-Google-Smtp-Source: ABdhPJzFaI3TsVQtt/9/YydWSVzg/UEgqgocaDLZ7Af/ms9c17a8uGntwS+iE+4wAFdpq0HXtTHPHA== X-Received: by 2002:a05:6402:b32:: with SMTP id bo18mr17708739edb.201.1596988704574; Sun, 09 Aug 2020 08:58:24 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:24 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:38 +0200 Message-Id: <20200809155748.30092-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/21] avfilter/af_amix: Fix double-free of AVFilterChannelLayouts on 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" The query_formats function of the amix filter tries to allocate a list of channel layouts which are attached to more permanent objects (an AVFilter's links) for storage afterwards on success. If attaching a list to a link succeeds, the link becomes one of the common owners of the list. Yet if a list has been successfully attached to links (or if there were no links to attach it to in which case ff_set_common_channel_layouts() already frees the list) and an error happens lateron, the list was manually freed, which is wrong, because the list has either already been freed or it is owned by its links in which case these links' pointers to their list will become dangling and there will be double-frees/uses-after-free when these links are cleaned up automatically. This commit fixes this by removing the custom freeing code; this is made possible by using the list in ff_set_common_channel_layouts() directly after its allocation (without anything that can fail in between). Notice that ff_set_common_channel_layouts() is buggy itself which can lead to double-frees on error. This is not fixed in this commit. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_amix.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c index 6a4ef8d944..cae9d4585a 100644 --- a/libavfilter/af_amix.c +++ b/libavfilter/af_amix.c @@ -593,25 +593,13 @@ static int query_formats(AVFilterContext *ctx) AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBLP, AV_SAMPLE_FMT_NONE }; - AVFilterChannelLayouts *layouts; int ret; - layouts = ff_all_channel_counts(); - if (!layouts) { - ret = AVERROR(ENOMEM); - goto fail; - } - if ((ret = ff_set_common_formats(ctx, ff_make_format_list(sample_fmts))) < 0 || - (ret = ff_set_common_channel_layouts(ctx, layouts)) < 0 || (ret = ff_set_common_samplerates(ctx, ff_all_samplerates())) < 0) - goto fail; - return 0; -fail: - if (layouts) - av_freep(&layouts->channel_layouts); - av_freep(&layouts); - return ret; + return ret; + + return ff_set_common_channel_layouts(ctx, ff_all_channel_counts()); } static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, From patchwork Sun Aug 9 15:57:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21555 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 0A0E644B9EE for ; Sun, 9 Aug 2020 18:58:35 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E48B268AD2F; Sun, 9 Aug 2020 18:58:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AAB1368AB04 for ; Sun, 9 Aug 2020 18:58:26 +0300 (EEST) Received: by mail-ed1-f65.google.com with SMTP id cq28so4504528edb.10 for ; Sun, 09 Aug 2020 08:58:26 -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=WiSLbgnFtV3Ki5KB+lkDqVP2zq5NgFieR5ydNI7i6xw=; b=YRBQf0xQiYRM4U7+WRIgqhFxnDOZzKWXpg5XXgw1SqeH/z4SFE7xKAXvGfS3Y8kDjP J4yK62QnXm95P0AMqlQ4OTvM/vF+TfMXz1gc9MU/kuFaJX1nEN/sCk7+V4qkrcnKMKXE fP/olz67Ros4kTsWx9hlj7Rl+lECBQgwEhDJ4UxZ2Zv+c7UvNRlhL98gunz+Pxa3kM+7 +ipEIqQ2yQXzhvGvwfyeGeYCzsyeMlbKpKPPNKm31TC3d/njlUBTzw651IL7AMqhzujD ZxG7GFHxsTKmQLJpAjSepnMgNGImt8GhQGcQ1svr8TVRJq1E1TpbBGVlUo+KxeEnvDTf QpoQ== 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=WiSLbgnFtV3Ki5KB+lkDqVP2zq5NgFieR5ydNI7i6xw=; b=eCUIer6dfij3MnpliAO+ZIpDQGVU1M3X1u+2++7pYGafOdu2/47yd0fOj5E25+UOcK KL5q56xcsj1czTIGXTLbhDMTG5eQivD5n3VcL3Ay17WhtPP0W0x71gwIXgajy2EvSFsK Qeihndxh1pS3oVH+WUv5EOixzcj51c8Rcj7MwfFMA6RjG/TOD7XtXUq9BK8IGogtbYGF EE6mbcW6hrRstlK4Og26UZuy+F+9GDJYItDe2nS4nwVh7+RQsphQ6I5bATFPoCYHmFVC x2g7ZnEmq3Kadu9mA36dMQH8s1D/aSN/QA0+gO5TjKQVLU0NU9PkWI0I7PJ6kjBVaD+K uTvg== X-Gm-Message-State: AOAM532LtIWLePadEghp10Ovd9jcQV7noHoJIP93qzeZ2/91Jl4nw7io Eq48jItc6HTcF5HwcQs9PjIyN2nl X-Google-Smtp-Source: ABdhPJzD+rrnODEfHtRFXmu5jrKm4s2ftqJvmU+sfWPpTo9vkSYMAV5FdnTE4/UtA2glXfwdfMD/Ow== X-Received: by 2002:a50:e087:: with SMTP id f7mr18122063edl.174.1596988705617; Sun, 09 Aug 2020 08:58:25 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:25 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:39 +0200 Message-Id: <20200809155748.30092-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/21] avfilter/vf_showpalette: Fix double-free of AVFilterFormats on 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" The query_formats function of the showpalette filter tries to allocate two lists of formats which on success are attached to more permanent objects (AVFilterLinks) for storage afterwards. If attaching a list to an AVFilterLink succeeds, the link becomes one (in this case the only one) of the owners of the list. Yet if attaching the first list to its link succeeds and attaching the second list fails, both lists were manually freed, which means that the first link's pointer to the first list becomes dangling and there will be a double-free when the first link is cleaned up automatically. This commit fixes this by removing the custom free code; this will temporarily add a leaking codepath (if attaching a list to a link fails, the list will leak), but this will be fixed shortly by making sure that an AVFilterFormats without owner will be automatically freed when attaching it to an AVFilterLink fails. Notice at most one list leaks because as of this commit a new list is only allocated after the old list has been successfully attached to a link. Signed-off-by: Andreas Rheinhardt --- libavfilter/vf_showpalette.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/libavfilter/vf_showpalette.c b/libavfilter/vf_showpalette.c index f715d6bc2c..c32dbd5b5d 100644 --- a/libavfilter/vf_showpalette.c +++ b/libavfilter/vf_showpalette.c @@ -46,26 +46,13 @@ static int query_formats(AVFilterContext *ctx) { static const enum AVPixelFormat in_fmts[] = {AV_PIX_FMT_PAL8, AV_PIX_FMT_NONE}; static const enum AVPixelFormat out_fmts[] = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE}; - int ret; - AVFilterFormats *in = ff_make_format_list(in_fmts); - AVFilterFormats *out = ff_make_format_list(out_fmts); - if (!in || !out) { - ret = AVERROR(ENOMEM); - goto fail; - } + int ret = ff_formats_ref(ff_make_format_list(in_fmts), + &ctx->inputs[0]->out_formats); + if (ret < 0) + return ret; - if ((ret = ff_formats_ref(in , &ctx->inputs[0]->out_formats)) < 0 || - (ret = ff_formats_ref(out, &ctx->outputs[0]->in_formats)) < 0) - goto fail; - return 0; -fail: - if (in) - av_freep(&in->formats); - av_freep(&in); - if (out) - av_freep(&out->formats); - av_freep(&out); - return ret; + return ff_formats_ref(ff_make_format_list(out_fmts), + &ctx->outputs[0]->in_formats); } static int config_output(AVFilterLink *outlink) From patchwork Sun Aug 9 15:57:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21557 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 0EF0F44B9EE for ; Sun, 9 Aug 2020 18:58:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EA4F668AD72; Sun, 9 Aug 2020 18:58:36 +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 AC03968A9E1 for ; Sun, 9 Aug 2020 18:58:27 +0300 (EEST) Received: by mail-ed1-f67.google.com with SMTP id q4so4663936edv.13 for ; Sun, 09 Aug 2020 08:58:27 -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=KjhhMRvuDQ18liC/kNXb9HrmbaKSGNocNmQenyL2zZE=; b=D0Q0elQUowzgidajEjZGBCq8zYkKHdjJCxSwMM0uxpbO3RG07OR90CZmtgIpKnvR3M dT6uHE/SCjxH8hKkh1rnDGoxu5W+EmaFoBkYx2TkrF/CwxAzxynbpkWGs3JMbSmcR5ii DlowP+IbzymdM1/jtSIjYNUOG6e4ffHtMaqYVeHTONFu2rBgfrKTwChjMyrmv2kBWaSX R+LEj8FsGaPZCPBUNdOlWekeyVpz7/vM4pwrJ9k/Ihj3UIsUX2ShmP+h8bmbD6pfL+bm Hf6skldSrv84onlkC/muGdEh3crPRWlM84t6GH4ZJxYg3yrzmcJ7SfuZmrrx9u2wuUA6 RkzQ== 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=KjhhMRvuDQ18liC/kNXb9HrmbaKSGNocNmQenyL2zZE=; b=WWRXRCdJePtHg7wOwKzkplgYUqWgfbQD8/LdyXqHJG9x/qnIP64zWu61do8iRyCF4I uXaHib55l/gVD+MaDc46QIb9GD6el+yNjSahP7zct74sPed/wMY+tnVATQbQ2eRG399+ ezJ3bzc1+YHfvVw7vRDsr4h5ApOpjRayL2XfbaIul+zW3I02dodPVY51fnonh1A1aJF9 Zro4wO6TKRZd0s4nFq6Q6jSYZ237W82/IkaOGkSoy1nC/EHfnXRAtzljaiAHO+v3C5sc kYlucOkwmZW+YjA3m7VKpbpGPy86zX5vEvF5HnN2QXBOcEv2IRYTmznENIc7Wzmk9yrT s3uA== X-Gm-Message-State: AOAM53122os5h97CfNxboGoMdVAiu7BNbSSuBm8nyGdCbcdBekJ28QfQ tUc8T5ozt+nNlzOC6LKzgI1wzY6n X-Google-Smtp-Source: ABdhPJywyrdxH2Y4w1MYcGKm0gNiMWmNhBBiBksA9bu6bDjVmjTe7tLVe75GB4v504A0cqKbkjachw== X-Received: by 2002:a05:6402:22d9:: with SMTP id dm25mr17167776edb.2.1596988706692; Sun, 09 Aug 2020 08:58:26 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:26 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:40 +0200 Message-Id: <20200809155748.30092-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/21] avfilter/vf_remap: Fix double-free of AVFilterFormats on 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" The query_formats function of the remap filter tries to allocate two lists of formats which on success are attached to more permanent objects (AVFilterLinks) for storage afterwards. If attaching a list to an AVFilterLink succeeds, it is in turn owned by the AVFilterLink (or more exactly, the AVFilterLink becomes one of the common owners of the list). Yet if attaching a list to one of its links succeeds and an error happens lateron, both lists were manually freed, which means that is wrong if the list is already owned by one or more links; these links' pointers to their lists will become dangling and there will be a double-free/use-after- free when these links are cleaned up automatically. This commit fixes this by removing the custom free code; this will temporarily add a leaking codepath (if attaching a list not already owned by a link to a link fails, the list will leak), but this will be fixed soon by making sure that an AVFilterFormats without owner will be automatically freed when attaching it to an AVFilterLink fails. Notice at most one list leaks because a new list is only allocated after the old list has been successfully attached to a link. Signed-off-by: Andreas Rheinhardt --- libavfilter/vf_remap.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/libavfilter/vf_remap.c b/libavfilter/vf_remap.c index 6d5d75225b..41a2409f21 100644 --- a/libavfilter/vf_remap.c +++ b/libavfilter/vf_remap.c @@ -115,25 +115,15 @@ static int query_formats(AVFilterContext *ctx) AVFilterFormats *pix_formats = NULL, *map_formats = NULL; int ret; - if (!(pix_formats = ff_make_format_list(s->format ? gray_pix_fmts : pix_fmts)) || - !(map_formats = ff_make_format_list(map_fmts))) { - ret = AVERROR(ENOMEM); - goto fail; - } + pix_formats = ff_make_format_list(s->format ? gray_pix_fmts : pix_fmts); if ((ret = ff_formats_ref(pix_formats, &ctx->inputs[0]->out_formats)) < 0 || - (ret = ff_formats_ref(map_formats, &ctx->inputs[1]->out_formats)) < 0 || - (ret = ff_formats_ref(map_formats, &ctx->inputs[2]->out_formats)) < 0 || (ret = ff_formats_ref(pix_formats, &ctx->outputs[0]->in_formats)) < 0) - goto fail; - return 0; -fail: - if (pix_formats) - av_freep(&pix_formats->formats); - av_freep(&pix_formats); - if (map_formats) - av_freep(&map_formats->formats); - av_freep(&map_formats); - return ret; + return ret; + + map_formats = ff_make_format_list(map_fmts); + if ((ret = ff_formats_ref(map_formats, &ctx->inputs[1]->out_formats)) < 0) + return ret; + return ff_formats_ref(map_formats, &ctx->inputs[2]->out_formats); } /** From patchwork Sun Aug 9 15:57:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21559 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 E851844B9EE for ; Sun, 9 Aug 2020 18:58:38 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D3FD668ACD0; Sun, 9 Aug 2020 18:58:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B1B1868AB1D for ; Sun, 9 Aug 2020 18:58:28 +0300 (EEST) Received: by mail-ej1-f67.google.com with SMTP id a26so7010854ejc.2 for ; Sun, 09 Aug 2020 08:58:28 -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=kURvikljlHkTYSzlSWfJJqqwV+ZYkAPiI3BVdTaXGcY=; b=ZpQ2yHfDwITQfEHQeFxn+NYypbGwRiDELS3uoT52zXIjQMQ75csHnnu++Yjz4HtqJ2 PwJH41cIDnXILjL5lJ6m0/PpN68th5NleHBWHqoGkQo2LdAzs6OtdpG6QCE3eq9im0fT 7yPvCu4xxd+f0JKWXNEa0fGoWtYYQo6/rwf5GcXCXBj+BRUunmTO1XZh8ox262l34u6H vbxJVBVjWHxpBN+1D9hF1/Jy4Gp4KxYv2Kzki19NzGSZkRt25fkypOONt0wRHckRpQV/ nkHDNnJBd9KLX0ZGVXNsGoyroUhWTqyeBzfXxAZ9/ExmrJpi/la7f2+jpA15mdCj5Mez RIgQ== 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=kURvikljlHkTYSzlSWfJJqqwV+ZYkAPiI3BVdTaXGcY=; b=YR+OPiSosifaU8QQEf7C30L6Ohd13wC3XfvAw7KPfllySe5xTJGTNXAZK5Mpds9+lV ryUPY72m0Ax0pT/YgfO/Y/+UtB+rDp3A/7Rn3W3mPX0E96+TS8j/vbs2o076tHAqc9e8 stg2vrsD9khZUxPCJYQwfeOb2fFvi/uS2XrkIJbtt35lHorcwdgedIXOOMsufgb4K+MK 4491QNAUJKa8gBTipTWC0S/sZRS6MoZ9rlVj3i4qm1F9s6/JBO/PbQKzKgdFMIxTchrz /GtB1Gep+RSseseXRpJHXxfLT2AwciMfTslFvFvqZ/z3RxSMG4YlCQ8+lyC/DamM4Vun Ic8A== X-Gm-Message-State: AOAM532iVqmbmTdjlNgEMR/EWHQ3BCy0mWVapMV3IzWC/TYZeKvhwHaj MK20byzKlp0MqTbouyhOGYFh8oms X-Google-Smtp-Source: ABdhPJwGVsSkwp/vwTInPVuLtcmJSijGdmiU8da82Lk78TwPM4CBL20qNYl9K5RH7S5/aw2Wsemuhw== X-Received: by 2002:a17:906:c1c3:: with SMTP id bw3mr19039372ejb.8.1596988707767; Sun, 09 Aug 2020 08:58:27 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:27 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:41 +0200 Message-Id: <20200809155748.30092-8-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/21] avfilter/vf_overlay: Fix double-free of AVFilterFormats on 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" The query_formats function of the overlay filter tries to allocate two lists (only one in a special case) of formats which on success are attached to more permanent objects (AVFilterLinks) for storage afterwards. If attaching a list to an AVFilterLink succeeds, it is in turn owned by the AVFilterLink (or more exactly, the AVFilterLink becomes one of the common owners of the list). Yet if attaching a list to one of its links succeeds and an error happens lateron, both lists were manually freed, whic is wrong if the list is already owned by one or more links; these links' pointers to their lists will become dangling and there will be a double-free/use-after-free when these links are cleaned up automatically. This commit fixes this by removing the custom freeing code; this will temporarily add a leaking codepath (if attaching a list not already owned by a link to a link fails, the list will leak), but this will be fixed soon by making sure that an AVFilterFormats without owner will be automatically freed when attaching it to an AVFilterLink fails. Notice that at most one list leaks because a new list is only allocated after the old list has been successfully attached to a link. Signed-off-by: Andreas Rheinhardt --- libavfilter/vf_overlay.c | 84 +++++++++++----------------------------- 1 file changed, 23 insertions(+), 61 deletions(-) diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c index b3a1ac1a09..324738635d 100644 --- a/libavfilter/vf_overlay.c +++ b/libavfilter/vf_overlay.c @@ -221,90 +221,52 @@ static int query_formats(AVFilterContext *ctx) AV_PIX_FMT_NONE }; - AVFilterFormats *main_formats = NULL; - AVFilterFormats *overlay_formats = NULL; + const enum AVPixelFormat *main_formats, *overlay_formats; + AVFilterFormats *formats; int ret; switch (s->format) { case OVERLAY_FORMAT_YUV420: - if (!(main_formats = ff_make_format_list(main_pix_fmts_yuv420)) || - !(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv420))) { - ret = AVERROR(ENOMEM); - goto fail; - } + main_formats = main_pix_fmts_yuv420; + overlay_formats = overlay_pix_fmts_yuv420; break; case OVERLAY_FORMAT_YUV420P10: - if (!(main_formats = ff_make_format_list(main_pix_fmts_yuv420p10)) || - !(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv420p10))) { - ret = AVERROR(ENOMEM); - goto fail; - } + main_formats = main_pix_fmts_yuv420p10; + overlay_formats = overlay_pix_fmts_yuv420p10; break; case OVERLAY_FORMAT_YUV422: - if (!(main_formats = ff_make_format_list(main_pix_fmts_yuv422)) || - !(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv422))) { - ret = AVERROR(ENOMEM); - goto fail; - } + main_formats = main_pix_fmts_yuv422; + overlay_formats = overlay_pix_fmts_yuv422; break; case OVERLAY_FORMAT_YUV422P10: - if (!(main_formats = ff_make_format_list(main_pix_fmts_yuv422p10)) || - !(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv422p10))) { - ret = AVERROR(ENOMEM); - goto fail; - } + main_formats = main_pix_fmts_yuv422p10; + overlay_formats = overlay_pix_fmts_yuv422p10; break; case OVERLAY_FORMAT_YUV444: - if (!(main_formats = ff_make_format_list(main_pix_fmts_yuv444)) || - !(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv444))) { - ret = AVERROR(ENOMEM); - goto fail; - } + main_formats = main_pix_fmts_yuv444; + overlay_formats = overlay_pix_fmts_yuv444; break; case OVERLAY_FORMAT_RGB: - if (!(main_formats = ff_make_format_list(main_pix_fmts_rgb)) || - !(overlay_formats = ff_make_format_list(overlay_pix_fmts_rgb))) { - ret = AVERROR(ENOMEM); - goto fail; - } + main_formats = main_pix_fmts_rgb; + overlay_formats = overlay_pix_fmts_rgb; break; case OVERLAY_FORMAT_GBRP: - if (!(main_formats = ff_make_format_list(main_pix_fmts_gbrp)) || - !(overlay_formats = ff_make_format_list(overlay_pix_fmts_gbrp))) { - ret = AVERROR(ENOMEM); - goto fail; - } + main_formats = main_pix_fmts_gbrp; + overlay_formats = overlay_pix_fmts_gbrp; break; case OVERLAY_FORMAT_AUTO: - if (!(main_formats = ff_make_format_list(alpha_pix_fmts))) { - ret = AVERROR(ENOMEM); - goto fail; - } - break; + return ff_set_common_formats(ctx, ff_make_format_list(alpha_pix_fmts)); default: av_assert0(0); } - if (s->format == OVERLAY_FORMAT_AUTO) { - ret = ff_set_common_formats(ctx, main_formats); - if (ret < 0) - goto fail; - } else { - if ((ret = ff_formats_ref(main_formats , &ctx->inputs[MAIN]->out_formats )) < 0 || - (ret = ff_formats_ref(overlay_formats, &ctx->inputs[OVERLAY]->out_formats)) < 0 || - (ret = ff_formats_ref(main_formats , &ctx->outputs[MAIN]->in_formats )) < 0) - goto fail; - } + formats = ff_make_format_list(main_formats); + if ((ret = ff_formats_ref(formats, &ctx->inputs[MAIN]->out_formats)) < 0 || + (ret = ff_formats_ref(formats, &ctx->outputs[MAIN]->in_formats)) < 0) + return ret; - return 0; -fail: - if (main_formats) - av_freep(&main_formats->formats); - av_freep(&main_formats); - if (overlay_formats) - av_freep(&overlay_formats->formats); - av_freep(&overlay_formats); - return ret; + return ff_formats_ref(ff_make_format_list(overlay_formats), + &ctx->inputs[OVERLAY]->out_formats); } static int config_input_overlay(AVFilterLink *inlink) From patchwork Sun Aug 9 15:57:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21560 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 0AB4944B9EE for ; Sun, 9 Aug 2020 18:58:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DE86268AE6E; Sun, 9 Aug 2020 18:58:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8183168AA08 for ; Sun, 9 Aug 2020 18:58:29 +0300 (EEST) Received: by mail-ed1-f66.google.com with SMTP id c10so4678148edk.6 for ; Sun, 09 Aug 2020 08:58:29 -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=V9Evqcs1HPqqDRcdSZ5EJdYz8OfODPhxVXZ/PgzmDhY=; b=AwA/h/7+frlH+SsZvUeuc+k/iiCUWWDjbV03pZPYNlbwuo4dcAK1wYYS3NWPyzuS6w FdnYNtpkNVjAv8PHtDOput9thgqU+ggpLsRXJHf9CwInIzNzi0M8xjSKSzRVnrbjTlec BKsZ2BMxXJawMfIecFyNscMdHWnexjFMJyrkz7Jx9M4AkAjXoJsT6EE0Yl+3gKBbeTFi RqEa3IV8vfTOIFmmzvA6g7LLOUIBzypntCLQxRZnIQSGdl+5AAhNsuHZWDAcoe4L9z8B BaXQgQ9pC0hwuVH1FFnHsuUrbuhT0cLwnwAmAwhL/MkiC+LrCegpp0SxAKGlIkFjZY9j 3s7w== 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=V9Evqcs1HPqqDRcdSZ5EJdYz8OfODPhxVXZ/PgzmDhY=; b=Pd4eGLhZRfxsmdZcwQKAOa0pIDSnuUDD9gV9tdoWAv1u5Z6KahaNuJu67TAS4wpPRX 26jv0CJLV0bei38NRk9eJv3PotXNsPvEgUIm99LmHIZ4IHrPnWd7/jZ+/BTMNc9b/j/k LdC9BslYS+TUMVYpl6amvWBA4KtDwQAl3OnFFJHyhGKSFTA+dlaxwrXmWTwzBC0MxfhD gG6PQAjeb6CPNYfyS3r9eKquw6mERSIAnvwBG+p8UAGR9uiCzVYTW/puVMNb9Y8pn1lR wHmhocmWwgSZkkMx+46Hn1KZR9FKRovGDZbegmzre+GEFNyCuA9c5ac7OouUPehG1NgQ pGyQ== X-Gm-Message-State: AOAM532mad35GPE+wD+mxRDb6ceGbsKIP3JMCL9MsA/G15o9wnH31Sjj IzBIAF3wSdhQySa+3R6cLpcg3Ztd X-Google-Smtp-Source: ABdhPJxsQKso1xyk6aXL4t8dMwj9m6eCwl9QJkUSr2I7hGUCQF3zlIKss7RNNwsxezizntCW3i49tw== X-Received: by 2002:a50:e004:: with SMTP id e4mr5974921edl.114.1596988708656; Sun, 09 Aug 2020 08:58:28 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:28 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:42 +0200 Message-Id: <20200809155748.30092-9-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/21] avfilter/vf_alphamerge: Fix double-free of AVFilterFormats on 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" The query_formats function of the alphamerge filter tries to allocate two lists of formats which on success are attached to more permanent objects (AVFilterLinks) for storage afterwards. If attaching a list to an AVFilterLink succeeds, the link becomes one of the owners of the list. Yet if attaching a list to one of its links succeeds and an error happens lateron, both lists were manually freed, which is wrong if the list is already owned by one or more links; these links' pointers to their lists will become dangling and there will be a double-free/use- after-free when these links are cleaned up automatically. This commit fixes this by removing the custom freeing code; this will temporarily add a leaking codepath (if attaching a list not already owned by a link to a link fails, the list will leak), but this will be fixed soon by making sure that an AVFilterFormats without owner will be automatically freed when attaching it to an AVFilterLink fails. At most one list leaks because as of this commit a new list is only allocated after the old list has been successfully attached to a link. Signed-off-by: Andreas Rheinhardt --- libavfilter/vf_alphamerge.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/libavfilter/vf_alphamerge.c b/libavfilter/vf_alphamerge.c index 85b6d9b61a..a509f10103 100644 --- a/libavfilter/vf_alphamerge.c +++ b/libavfilter/vf_alphamerge.c @@ -55,27 +55,15 @@ static int query_formats(AVFilterContext *ctx) AV_PIX_FMT_NONE }; static const enum AVPixelFormat alpha_fmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE }; - AVFilterFormats *main_formats = NULL, *alpha_formats = NULL; + AVFilterFormats *main_formats = ff_make_format_list(main_fmts); int ret; - if (!(main_formats = ff_make_format_list(main_fmts)) || - !(alpha_formats = ff_make_format_list(alpha_fmts))) { - ret = AVERROR(ENOMEM); - goto fail; - } - if ((ret = ff_formats_ref(main_formats , &ctx->inputs[0]->out_formats)) < 0 || - (ret = ff_formats_ref(alpha_formats, &ctx->inputs[1]->out_formats)) < 0 || - (ret = ff_formats_ref(main_formats , &ctx->outputs[0]->in_formats)) < 0) - goto fail; - return 0; -fail: - if (main_formats) - av_freep(&main_formats->formats); - av_freep(&main_formats); - if (alpha_formats) - av_freep(&alpha_formats->formats); - av_freep(&alpha_formats); - return ret; + if ((ret = ff_formats_ref(main_formats, &ctx->inputs[0]->out_formats)) < 0 || + (ret = ff_formats_ref(main_formats, &ctx->outputs[0]->in_formats)) < 0) + return ret; + + return ff_formats_ref(ff_make_format_list(alpha_fmts), + &ctx->inputs[1]->out_formats); } static int config_input_main(AVFilterLink *inlink) From patchwork Sun Aug 9 15:57:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21562 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 230C844B9EE for ; Sun, 9 Aug 2020 18:58:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0688968AFB8; Sun, 9 Aug 2020 18:58:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6328368AD4D for ; Sun, 9 Aug 2020 18:58:30 +0300 (EEST) Received: by mail-ej1-f67.google.com with SMTP id jp10so7022912ejb.0 for ; Sun, 09 Aug 2020 08:58:30 -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=BfMTNZbRBFJKGWHlHxb+tGx9/vYbPNhm4kytq8ERRBE=; b=bBeMwHgUM1/4JZ+NN8X3Al5myQ1ZlifFohIugjR0Q5oAVscD+wbib23PfHwPVcbli4 xdKtZIDUHAIEz1QmArcM0qB2ZByi8wR0eYpocnha7fjeZlGmaMghhaFbD1yLvZ6B79ta Isl5XtlgB/VhHPfxiLJc5y9BUX3F7HcQNOLvTLi6CF4vdv6cfNfxBaOYy8quTL7gFmx3 BPhU0apuk+jog6N2eQOAYcMmaCS/t6QP7RjDqlOKbrZEc9mkyV7q0nVgaWQ29Gdg3deb pyePvkhCB3nHhZNf8Czidzrkjdz7iclw1w63RSOMRRDqpwF2dB1haf4qTS9F5ktkRxeQ Nxwg== 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=BfMTNZbRBFJKGWHlHxb+tGx9/vYbPNhm4kytq8ERRBE=; b=r7aU846mzx8wnRDvNSP3e+BUJSP3A5qGr9awkvbLtkJ9uC3uAVAZ2wywliBPhCqWMd pGSIu1B4yzirN1e1JkvY7AIWmOJB5cQP2m9+bR/P2K/XTAzRFv2TXonPm/vO6MNeql2H HwS/LubtHBEJuuH58fYaRd4WO1VJL+rZAfdYiT2u3C//GhoVWoJL2VMJ1A7J1zH5QQST 46eEIrDGmyH+qu8gS8A0fT5L1rJ7fLgdjZP0SDZ/KKdV+BUzgPaTa/uMIxjUncG/K3VD yM8DKSjs9x9vGGxw4mG0D9TdpB2eNme334FmOVX/H8c4GqLrKdQvWRX1Fgscrqx/4Vap Q39w== X-Gm-Message-State: AOAM531Dm2rRg+Vx8C3roY50OVBxEeqJny4J7aEAEFTrBEb3znyNeyiR rLdSe8U/oYYtteqChYzPuR1Gp1j2 X-Google-Smtp-Source: ABdhPJwzlfV5loNF6wUMYRQQRzBbgsEKbr1Slgj31AfT9GWauzeMl19LtSItERUqks7/OfenQ2PvWg== X-Received: by 2002:a17:906:819:: with SMTP id e25mr19002324ejd.95.1596988709546; Sun, 09 Aug 2020 08:58:29 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:29 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:43 +0200 Message-Id: <20200809155748.30092-10-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/21] avfilter/af_channelmap: Fix double-free of AVFilterChannelLayouts on 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" The query_formats function of the channelmap filter tries to allocate a list of channel layouts which on success are attached to more permanent objects (an AVFilterLink) for storage afterwards. If attaching succeeds, the link becomes one of the common owners (in this case, the only owner) of the list. Yet if the list has been successfully attached to the link and an error happens lateron, the list was manually freed, which is wrong, because it is owned by its link so that the link's pointer to the list will become dangling and there will be a double-free/use-after-free when the link is later cleaned up automatically. This commit fixes this by removing the custom freeing code; this will temporarily add a leaking codepath (if attaching the list fails, the list will leak), but this will be fixed soon by making sure that an AVFilterChannelLayouts without owner will be automatically freed when attaching it to an AVFilterLink fails. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_channelmap.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/libavfilter/af_channelmap.c b/libavfilter/af_channelmap.c index 285d76a3ef..1f79f89ce3 100644 --- a/libavfilter/af_channelmap.c +++ b/libavfilter/af_channelmap.c @@ -280,28 +280,18 @@ static av_cold int channelmap_init(AVFilterContext *ctx) static int channelmap_query_formats(AVFilterContext *ctx) { ChannelMapContext *s = ctx->priv; - AVFilterChannelLayouts *layouts; AVFilterChannelLayouts *channel_layouts = NULL; int ret; - layouts = ff_all_channel_counts(); - if (!layouts) { - ret = AVERROR(ENOMEM); - goto fail; - } - if ((ret = ff_add_channel_layout (&channel_layouts, s->output_layout )) < 0 || - (ret = ff_set_common_formats (ctx , ff_planar_sample_fmts() )) < 0 || + if ((ret = ff_set_common_formats (ctx, ff_planar_sample_fmts())) < 0 || (ret = ff_set_common_samplerates (ctx , ff_all_samplerates() )) < 0 || - (ret = ff_channel_layouts_ref (layouts , &ctx->inputs[0]->out_channel_layouts)) < 0 || - (ret = ff_channel_layouts_ref (channel_layouts , &ctx->outputs[0]->in_channel_layouts)) < 0) - goto fail; + (ret = ff_add_channel_layout(&channel_layouts, s->output_layout)) < 0 || + (ret = ff_channel_layouts_ref(channel_layouts, + &ctx->outputs[0]->in_channel_layouts)) < 0) + return ret; - return 0; -fail: - if (layouts) - av_freep(&layouts->channel_layouts); - av_freep(&layouts); - return ret; + return ff_channel_layouts_ref(ff_all_channel_counts(), + &ctx->inputs[0]->out_channel_layouts); } static int channelmap_filter_frame(AVFilterLink *inlink, AVFrame *buf) From patchwork Sun Aug 9 15:57:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21556 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 2539044B9EE for ; Sun, 9 Aug 2020 18:58:36 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0C8C968A56E; Sun, 9 Aug 2020 18:58:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E735368A9E1 for ; Sun, 9 Aug 2020 18:58:31 +0300 (EEST) Received: by mail-ed1-f66.google.com with SMTP id a14so4684768edx.7 for ; Sun, 09 Aug 2020 08:58:31 -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=Yb+OdrOzbcItYCRCz5PtdK1OOEH8WJqaSXSv0mgyvlA=; b=PXP1K/22mKdsDGC8PE93fgEnE8dorHzSz5hrQpPTovYdu9ikiZFG+IJ6Kr/u7aUC9v /givAl/1C/g+461CuemPKe1McOwu5zWrWDuyKVwIuokAvS1jFrGrVrjes6F6Z3PWZw6d zUt/9IbGXRzu367qL+pKbHpO1z+jnndHQJjyTvujIygHvYKwBq9TNHUZaSOWQdULZSYy IAPJwNVt2w6cJM4lNm5J19Ui0onTDR1lFLXZ/g0kED1P3PxEw3l2iX1eaw51X6uEOPz/ dKRuZIywVZ6mv0LrEO18DR/vquHupE+zWWu+Qol3J9qfLGySOeyuUk4lUUdXsxnOWzyc WGSQ== 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=Yb+OdrOzbcItYCRCz5PtdK1OOEH8WJqaSXSv0mgyvlA=; b=TZjx9hdmWANax0Wz/+VSM1T2uyUjBYq2PBgGLhFecIVMtxYBI6Ik28Rz/2z7SpXM1x 7UhwDVcU9N6R8fSQclzUgj89/tpXkWv4MQIJQy6+GbnFnFMIh4RQLFe559Hte377GRnZ K7ECok9OavjKSJEF2QDoVgUSy9y0dmr+6BRdDoWdGwibJn0YN/yzer6L8PTUiEEuGNPY C42IJ/9eMvyk7TsC52urE1V5lp3ahD/5jMfvX0sU8DH9DdIXKERI4bWxOfTq3GftHFAO I6ixzr45B/BsJZQoa1GABBR5Pk1f55VUB6ARqmEla70px0FIlQfArmR0pextJBphMR22 eHeQ== X-Gm-Message-State: AOAM531hPLEF3YeVpbynFsIWO58BJv+hsxfe4pW68PZ5OAagDX1dFPxA CR04/Wt/F0JQME3ZWlqSzIJZu3Kv X-Google-Smtp-Source: ABdhPJxRXLph5ljV2kDXlCNftlrwU18bP0IjDFAHFHXomXfDo4yw00kPc0Om0O3nwPH9sQ16JcyoDw== X-Received: by 2002:aa7:cb45:: with SMTP id w5mr17478932edt.77.1596988710740; Sun, 09 Aug 2020 08:58:30 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.58.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:30 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:44 +0200 Message-Id: <20200809155748.30092-11-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/21] avfilter/formats: Fix double frees and memleaks on 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" The formats API deals with lists of channel layouts, sample rates, pixel formats and sample formats. These lists are refcounted in a way in which the list structure itself contains pointers to all of its owners. Furthermore, it is possible for a list to be not owned by anyone yet; this status is temporary until the list has been attached to an owner. Adding an owner to a list involves reallocating the list's list of owners and can therefore fail. In order to reduce the amount of checks and cleanup code for the users of this API, the API is supposed to be lenient when faced with input lists that are NULL and it is supposed to clean up if adding an owner to a list fails, so that a simple use case like list = ff_make_format_list(foo_fmts); if ((ret = ff_formats_ref(list, &ctx->inputs[0]->out_formats)) < 0) return ret; needn't check whether list could be successfully allocated (ff_formats_ref() return AVERROR(ENOMEM) if it couldn't) and it also needn't free list if ff_formats_ref() couldn't add an owner for it. But the cleaning up after itself was broken. The root cause was that the refcount was decremented during unreferencing whether or not the element to be unreferenced was actually an owner of the list or not. This means that if the above sample code is continued by if ((ret = ff_formats_ref(list, &ctx->inputs[1]->out_formats)) < 0) return ret; and that if an error happens at the second ff_formats_ref() call, the automatic cleaning of list will decrement the refcount from 1 (the sole owner of list at this moment is ctx->input[0]->out_formats) to 0 and so the list will be freed; yet ctx->input[0]->out_formats still points to the list and this will lead to a double free/use-after-free when ctx->input[0] is freed later. Presumably in order to work around such an issue, commit 93afb338a405eac0f9e7b092bc26603378bfcca6 restricted unreferencing to lists with owners. This does not solve the root cause (the above example is not fixed by this) at all, but it solves some crashs. This commit fixes the API: The list's refcount is only decremented if an owner is removed from the list of owners and not if the unref-function is called with a pointer that is not among the owners of the list. Furtermore, the requirement for the list to have owners is dropped. This implies that if the first call to ff_formats_ref() in the above example fails, the refcount which is initially zero during unreferencing is not modified, so that the list will be freed automatically in said call to ff_formats_ref() as every list whose refcount reaches zero is. If on the other hand, the second call to ff_formats_ref() is the first to fail, the refcount would stay at one during the automatic unreferencing in ff_formats_ref(). The list would later be freed when its last (and in this case sole) owner (namely ctx->inputs[0]->out_formats) gets unreferenced. The issues described here for ff_formats_ref() also affected the other functions of this API. E.g. ff_add_format() failed to clean up after itself if adding an entry to an already existing list failed (the case of a freshly allocated list was handled specially and this commit also removes said code). E.g. ff_all_formats() inherited the flaw. Signed-off-by: Andreas Rheinhardt --- The count variable in SET_COMMON_FORMATS is now btw unnecessary; it would be safe to always unref fmt in this macro (which does nothing except when fmt has no owner in which case it frees fmt). libavfilter/formats.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 3118aa0925..2379be1518 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -327,7 +327,6 @@ AVFilterChannelLayouts *avfilter_make_format64_list(const int64_t *fmts) #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \ do { \ type *fmts; \ - void *oldf = *f; \ \ if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) { \ return AVERROR(ENOMEM); \ @@ -337,8 +336,6 @@ do { \ sizeof(*(*f)->list)); \ if (!fmts) { \ unref_fn(f); \ - if (!oldf) \ - av_freep(f); \ return AVERROR(ENOMEM); \ } \ \ @@ -499,16 +496,17 @@ do { \ do { \ int idx = -1; \ \ - if (!ref || !*ref || !(*ref)->refs) \ + if (!ref || !*ref) \ return; \ \ FIND_REF_INDEX(ref, idx); \ \ - if (idx >= 0) \ + if (idx >= 0) { \ memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \ sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \ - \ - if(!--(*ref)->refcount) { \ + --(*ref)->refcount; \ + } \ + if (!(*ref)->refcount) { \ av_free((*ref)->list); \ av_free((*ref)->refs); \ av_free(*ref); \ @@ -550,7 +548,7 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref) FORMATS_CHANGEREF(oldref, newref); } -#define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref_fn, unref_fn, list) \ +#define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref_fn, unref_fn) \ int count = 0, i; \ \ if (!fmts) \ @@ -560,10 +558,6 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref) if (ctx->inputs[i] && !ctx->inputs[i]->out_fmts) { \ int ret = ref_fn(fmts, &ctx->inputs[i]->out_fmts); \ if (ret < 0) { \ - unref_fn(&fmts); \ - if (fmts) \ - av_freep(&fmts->list); \ - av_freep(&fmts); \ return ret; \ } \ count++; \ @@ -573,10 +567,6 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref) if (ctx->outputs[i] && !ctx->outputs[i]->in_fmts) { \ int ret = ref_fn(fmts, &ctx->outputs[i]->in_fmts); \ if (ret < 0) { \ - unref_fn(&fmts); \ - if (fmts) \ - av_freep(&fmts->list); \ - av_freep(&fmts); \ return ret; \ } \ count++; \ @@ -584,9 +574,7 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref) } \ \ if (!count) { \ - av_freep(&fmts->list); \ - av_freep(&fmts->refs); \ - av_freep(&fmts); \ + unref_fn(&fmts); \ } \ \ return 0; @@ -595,14 +583,14 @@ int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *layouts) { SET_COMMON_FORMATS(ctx, layouts, in_channel_layouts, out_channel_layouts, - ff_channel_layouts_ref, ff_channel_layouts_unref, channel_layouts); + ff_channel_layouts_ref, ff_channel_layouts_unref); } int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates) { SET_COMMON_FORMATS(ctx, samplerates, in_samplerates, out_samplerates, - ff_formats_ref, ff_formats_unref, formats); + ff_formats_ref, ff_formats_unref); } /** @@ -613,7 +601,7 @@ int ff_set_common_samplerates(AVFilterContext *ctx, int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats) { SET_COMMON_FORMATS(ctx, formats, in_formats, out_formats, - ff_formats_ref, ff_formats_unref, formats); + ff_formats_ref, ff_formats_unref); } static int default_query_formats_common(AVFilterContext *ctx, From patchwork Sun Aug 9 15:57:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21558 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 C30C644B9EE for ; Sun, 9 Aug 2020 18:58:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AF09F68AA6B; Sun, 9 Aug 2020 18:58:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A8E4668A8E9 for ; Sun, 9 Aug 2020 18:58:32 +0300 (EEST) Received: by mail-ej1-f67.google.com with SMTP id kq25so6999040ejb.3 for ; Sun, 09 Aug 2020 08:58:32 -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=lGKrGOklLPCveUdtTEXHmWOhd+GfUW98+i6TqWDJiyw=; b=Vo7LLx0jyAySQwy450r8F0FqAVLLJNDhRtC0S/Eb5DRtXRWvbsJjI1/CVnru/P5fzN UOEMhzAj0lwL5Bxtx+0HFm6zHVFWi6N++kOHK4HNv+fjLu6tZG6UziehlmGMDvWD0Wkp T7/BSLHOyvxUXHVZp92wBE3Xc8UCOQMvjTSdebAu4SZc+Xfv6JCHfoOdgDGObqxuHFZu jphzKpFdi0YF2hrXvN8JG5HXSju0/U8itCB7M27uEtajRyqp4YdmiscyG4IwawTgBr3F gMWHU+OXuMPQL2rtFV1sBf0+ZiXKXa+O3vZZ07CmMsTAmDkuBlT9FFqhEMP0qwDjujyB CfxQ== 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=lGKrGOklLPCveUdtTEXHmWOhd+GfUW98+i6TqWDJiyw=; b=EzItFHeE6HApdECRqBx7DW8K9/K+XA4v7ndw0MifoFvDRjEOazeDVmkwHDCZT2kvPR WlE7d2a8nK07oLfxr6vgm9D9KbVGIqxsRNZ9OYddDUQw4As74X0D+xMrRwHx+gZx1uuJ I4IRaZOfVYfhxgjUFQpafhYMzn12govBLkMcWZeuQBYxW1ym34Y9FmfwRtVo43BsFp77 ps0AaZVl0fUO6UiEQW5tdjQRIux1Tj76dXl9CmVTZuU+5m9+FGB3O8gCbdJgJXyTpkmV pKGL6bbdU4/fLlsCrhtMWzYddrkVH0ls4lwlWoBsGxiYhrrIZQ0c0QG1NKEiFskz1i0d /yIQ== X-Gm-Message-State: AOAM53153BKHNF7PWfaLV0bMQgcYHUCUZxSRkqiom8uYMk18v36MJW1p tcP0mTtAJYKvJDUfezcm+XHet6PN X-Google-Smtp-Source: ABdhPJyLq7ZEVLI+MR1kUR55jjdpOdsonft4uQK/zrwH1goYmGji/pvp1fwvs62NYJK5S29XmE+kTg== X-Received: by 2002:a17:906:6406:: with SMTP id d6mr17618569ejm.30.1596988711740; Sun, 09 Aug 2020 08:58:31 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:31 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:45 +0200 Message-Id: <20200809155748.30092-12-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/21] avfilter/vf_hwdownload: Fix leak of formats list upon 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" Signed-off-by: Andreas Rheinhardt --- libavfilter/vf_hwdownload.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_hwdownload.c b/libavfilter/vf_hwdownload.c index 33af30cf40..ce10b60e59 100644 --- a/libavfilter/vf_hwdownload.c +++ b/libavfilter/vf_hwdownload.c @@ -55,11 +55,11 @@ static int hwdownload_query_formats(AVFilterContext *avctx) } } - if ((err = ff_formats_ref(infmts, &avctx->inputs[0]->out_formats)) < 0 || - (err = ff_formats_ref(outfmts, &avctx->outputs[0]->in_formats)) < 0) + if ((err = ff_formats_ref(infmts, &avctx->inputs[0]->out_formats)) < 0) { + ff_formats_unref(&outfmts); return err; - - return 0; + } + return ff_formats_ref(outfmts, &avctx->outputs[0]->in_formats); } static int hwdownload_config_input(AVFilterLink *inlink) From patchwork Sun Aug 9 15:57: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: 21563 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 3810044B9EE for ; Sun, 9 Aug 2020 18:58:43 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 17FD368B00B; Sun, 9 Aug 2020 18:58:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 654C968AD50 for ; Sun, 9 Aug 2020 18:58:33 +0300 (EEST) Received: by mail-ej1-f51.google.com with SMTP id o23so7008504ejr.1 for ; Sun, 09 Aug 2020 08:58:33 -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=Gmxo+cjXERpOug11FUZBprj8GcUAOzebnaRy4eaJ8NI=; b=jNbnwh9CMiYnUAUMBGEGQh08DiTQFmza53mP4+HykhT8Jk/Elyz7Kug2dsgKYznTkf NNwDmf0I1OV6I3m+vdk9SOS6uYjLVeXKi6ohIvq4PeZi/ObOEHKvIk+n4h9fG2hLLxaQ 6tCvKlllOIbj/dUfxDWGmf+FxT3xqXwwtzb0Nsor4k7oDNoNLn0j3geUrQsiDcnkCfxN TMx0mtrYgMzmlwBDOBmLaXjbVYps+1zQJlOzaHu1p4VoV56EHXsaBu9nabkWr0hUNDDZ whsRBg3E1+5IF/Ox97SzJdE6u9rt0wG37Dn+TwDaLjuRvDlaGa3bYrsAcYvairzjDaq2 uxMw== 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=Gmxo+cjXERpOug11FUZBprj8GcUAOzebnaRy4eaJ8NI=; b=kcfYonhrXQYdJjDKINgH6pc/5jh4WgPgC7v77H+aNMKij2Uoeiy1syX9Y/w3s6BPzm Krj6shequQCP+yDXkagpTkjGFskA4QbhFrEAELIoPxIo9YiugL19ukxu62Nvr4hkjcOs ohDaUcKRGqur5O6WfL89ZrvBFAezy/ajOWQR/x8UYcdnu1CqC3LaKNPLTBoES0Ll/T8U DWs7ekvm+/YEyd4NRdNDXFHdkIA3CvQVevna1lD5aQ4Ii4in2Kn8QPtqUVouq6vZ8qWb e5sgZiI8HBqKpYH5VNJ/ty9YPEhFSHC5q2Yv9DJDcHVl3by2sduEXv/rsj4Oo1zjY4Vs sx/g== X-Gm-Message-State: AOAM533HDWuahTeMpcFoHTAOAXDwCk4SaDgZW2yDfx2xW1xI9yUz4KUu 5LQadtWTD/kkERhAd8CIb9v+eAdJ X-Google-Smtp-Source: ABdhPJwHkrFUq4HueNB84ldlyFSlt6swqwjwHZf8ujy6hYza6VTnVpKNuSmE1Qde4sYwkATngaeqLw== X-Received: by 2002:a17:906:c2c8:: with SMTP id ch8mr17567744ejb.161.1596988712827; Sun, 09 Aug 2020 08:58:32 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.58.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:32 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:46 +0200 Message-Id: <20200809155748.30092-13-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/21] avfilter: Remove redundant ff_formats/channel_layouts_unref() 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" ff_add_format() and ff_add_channel_layout() already unref the list upon error. Signed-off-by: Andreas Rheinhardt --- These ff_formats/channel_layouts_unref() also didn't do anything before this patchset, as none of these lists has any owner. libavfilter/af_aformat.c | 9 ++++----- libavfilter/vf_shuffleplanes.c | 1 - libavfilter/vf_weave.c | 1 - 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c index 1a702778c3..0ea470014c 100644 --- a/libavfilter/af_aformat.c +++ b/libavfilter/af_aformat.c @@ -60,7 +60,7 @@ static const AVOption aformat_options[] = { AVFILTER_DEFINE_CLASS(aformat); -#define PARSE_FORMATS(str, type, list, add_to_list, unref_fn, get_fmt, none, desc) \ +#define PARSE_FORMATS(str, type, list, add_to_list, get_fmt, none, desc) \ do { \ char *next, *cur = str, sep; \ int ret; \ @@ -83,7 +83,6 @@ do { \ return AVERROR(EINVAL); \ } \ if ((ret = add_to_list(&list, fmt)) < 0) { \ - unref_fn(&list); \ return ret; \ } \ \ @@ -102,11 +101,11 @@ static av_cold int init(AVFilterContext *ctx) AFormatContext *s = ctx->priv; PARSE_FORMATS(s->formats_str, enum AVSampleFormat, s->formats, - ff_add_format, ff_formats_unref, av_get_sample_fmt, AV_SAMPLE_FMT_NONE, "sample format"); - PARSE_FORMATS(s->sample_rates_str, int, s->sample_rates, ff_add_format, ff_formats_unref, + ff_add_format, av_get_sample_fmt, AV_SAMPLE_FMT_NONE, "sample format"); + PARSE_FORMATS(s->sample_rates_str, int, s->sample_rates, ff_add_format, get_sample_rate, 0, "sample rate"); PARSE_FORMATS(s->channel_layouts_str, uint64_t, s->channel_layouts, - ff_add_channel_layout, ff_channel_layouts_unref, av_get_channel_layout, 0, + ff_add_channel_layout, av_get_channel_layout, 0, "channel layout"); return 0; diff --git a/libavfilter/vf_shuffleplanes.c b/libavfilter/vf_shuffleplanes.c index 6c718893ce..c5a376d50b 100644 --- a/libavfilter/vf_shuffleplanes.c +++ b/libavfilter/vf_shuffleplanes.c @@ -64,7 +64,6 @@ static int query_formats(AVFilterContext *ctx) if (i != 4) continue; if ((ret = ff_add_format(&formats, fmt)) < 0) { - ff_formats_unref(&formats); return ret; } } diff --git a/libavfilter/vf_weave.c b/libavfilter/vf_weave.c index 8951b09095..8d4eb3d5a4 100644 --- a/libavfilter/vf_weave.c +++ b/libavfilter/vf_weave.c @@ -60,7 +60,6 @@ static int query_formats(AVFilterContext *ctx) if (!(desc->flags & AV_PIX_FMT_FLAG_PAL) && !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) { if ((ret = ff_add_format(&formats, fmt)) < 0) { - ff_formats_unref(&formats); return ret; } } From patchwork Sun Aug 9 15:57:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21561 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 EC66444B9EE for ; Sun, 9 Aug 2020 18:58:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D450768AD77; Sun, 9 Aug 2020 18:58:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D124168AA08 for ; Sun, 9 Aug 2020 18:58:34 +0300 (EEST) Received: by mail-ed1-f66.google.com with SMTP id a14so4684809edx.7 for ; Sun, 09 Aug 2020 08:58:34 -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=5f3IzmWCGskDTfHqb7WqpVASxmILidKJJrAhQeBE51A=; b=eZKDU9eLh0hMgsXAL+gSjttaOsbiSaYuRcYkIwJoOoqoXcdo4ZyeggbwrFP6S/joaT OP0UABbBpX1QG8icEXyeqo611+1tAkIuX+sS9KpDq3N9IGQB0j1QjfHTmCMMWC4qc6DX ke99R9jY2KZX1KxIvpsASIFnQRXXtpgUQLsCXxyLAWfhliCYwhTbZmqJKAFjwzXSJDV+ ATXbWaslaGHws6wJFxaId5F7WpeLwbBfMmEJ4FToW+QBynpS9K2Na2B5E5IO1JvyPtyT JpiK0129uYvvv0jnGTTIeof9D4HLih0m7T1LGDx8b42+NyvSrr1p1OTcFNQnOATWYmfh +NtQ== 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=5f3IzmWCGskDTfHqb7WqpVASxmILidKJJrAhQeBE51A=; b=JEeepwMQtAkldaXO3IvdpZE0zA/M7Qaz6L1vi4Toqv2NMAowROfTObwNbb8lRBhaYu 0a0B56uSfFVXSvET4rWKWzmhqzyUxV5vkj1dtxUBbNwXTBOyADjrHD2nKzrH30msMMbn 6FBwIjU7RgOFOjPzRF2VUpFmq6Mxfe/SAIr0ArYOGRpD893V9UF33ke7s48Syf6fzfFD LkD8uqT3o0fwunzgc/2W9g1WzCnjCIrCPuCZrNm7a98xiaFP64z8e0RPRGMpRMHb3lzc inBD/A0M864mPrnRnsXEY5Za00nsV61sBltd315mSnwqBdJ9iqzzNo52OJ5NqugAscpV gXHg== X-Gm-Message-State: AOAM530ZxKiLCXQcoN3XtEMpa8o6wNgkUdN+ymMoW2W6UOOVB3Myr/Xd JDyxoNous9WnxOXJc7tIqUFrCR/D X-Google-Smtp-Source: ABdhPJyG99pALQzhNMMt/2b7XdVm+KDst9Zzugv8UO8dm3kO8UgmH/FVi4lvOqKGJRwQuPnkCc+USg== X-Received: by 2002:aa7:d809:: with SMTP id v9mr17521484edq.94.1596988713937; Sun, 09 Aug 2020 08:58:33 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.58.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:33 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:47 +0200 Message-Id: <20200809155748.30092-14-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/21] avfilter/avfiltergraph: Remove unused macro parameter 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" Signed-off-by: Andreas Rheinhardt --- libavfilter/avfiltergraph.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index a149f8fb6d..681c519ef0 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -748,7 +748,7 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref) return 0; } -#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format, unref_format) \ +#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \ do { \ for (i = 0; i < filter->nb_inputs; i++) { \ AVFilterLink *link = filter->inputs[i]; \ @@ -790,9 +790,9 @@ static int reduce_formats_on_filter(AVFilterContext *filter) int i, j, k, ret = 0; REDUCE_FORMATS(int, AVFilterFormats, formats, formats, - nb_formats, ff_add_format, ff_formats_unref); + nb_formats, ff_add_format); REDUCE_FORMATS(int, AVFilterFormats, samplerates, formats, - nb_formats, ff_add_format, ff_formats_unref); + nb_formats, ff_add_format); /* reduce channel layouts */ for (i = 0; i < filter->nb_inputs; i++) { From patchwork Sun Aug 9 15:57:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21564 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 4B5A944B9EE for ; Sun, 9 Aug 2020 18:58:44 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2CD6768B0EE; Sun, 9 Aug 2020 18:58:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1DC9168AD4C for ; Sun, 9 Aug 2020 18:58:36 +0300 (EEST) Received: by mail-ej1-f68.google.com with SMTP id qc22so6994558ejb.4 for ; Sun, 09 Aug 2020 08:58:35 -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=Qa7vKjEG+1k5rVg5t++hHP1KPlip+YA3jGrFz57EuL4=; b=gqaHaeKLvfsMbP5YPgEAxyKzb3aOD+5mNaOac5GhqTJW1npZkjn1GF7MZLtx740Qo7 WhiszWVljWOCjq9mAzSKppyzP81Jg+sAxwk9msoN7LIK6UAZLqDU4+m/IDQTZVfJFF+s NNMkYpdS7yw+quSpFqSyhgnf5b22bNI9iJVKeC0u7vqg9ePG7apVt46RrkK6oSZ3EFqj ElCxUjJMu7TXDp2EyczKi9b+uuSHIgkx0jxYLrloMhAl1GKzmiVowvDjNfMMtny2merO HOSxWqpzguHnKWDCm2pfSm+OgCMo7L5TezuZ0gqLzyV6RDBMTX8Ays1NMV1JiHdzdD/d gi9g== 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=Qa7vKjEG+1k5rVg5t++hHP1KPlip+YA3jGrFz57EuL4=; b=I0001jCMjJulKtFK8yBLcwd/MZbTxxL34HGLN8JiXIZL76w3eJ3kxQrtPoaNyTmpLn MAQrsCnW2uk4+g6ZX+ejgy3NqyFsKnjAMXrby9R5Jk5GCcUqooDpJuNMmmjEUs/OnRJn cHyVke0S425ay0W+tvOwiYccn8/8owb6Cuu18vCAD01haXTv9qFwThpy14BZM22Ke9XT AVOi2ATyVNBkgoAYCnkFfuhQbBh7/p+MeHlhfAJlVNLrfNJKOXAijqAyYdpIPkAxnMAx P/NnwZVDz9jVgyEwR/8V3DipnbXzlPDI8w8vRcMd9oBvK0hxLnS2BiuY99/ZvMULb0w6 JVCA== X-Gm-Message-State: AOAM531LdhkHoZ1bDGkEcrqFiuh8l28czXeuP6iU/6xHXE+rrCeT4F6U 8ED19pCqrFifg1Qoh2hsJyPgtoyn X-Google-Smtp-Source: ABdhPJx+e4yGhT+/m116X2VcNZ6XLbaYtQ8RtD7o+Drezzsw7rDnz63eTkorM8NgJXDrBRP1ynjtoA== X-Received: by 2002:a17:906:824d:: with SMTP id f13mr13628297ejx.190.1596988715133; Sun, 09 Aug 2020 08:58:35 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id g11sm5360290edv.95.2020.08.09.08.58.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 08:58:34 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Aug 2020 17:57:48 +0200 Message-Id: <20200809155748.30092-15-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 21/21] avfilter/af_aformat: Add uninit function 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" Fixes memleaks in case init fails (e.g. because of invalid parameters like 'aformat=sample_fmts=s16:cl=wtf') or also if query_formats is never called. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_aformat.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c index 0ea470014c..e669f2de83 100644 --- a/libavfilter/af_aformat.c +++ b/libavfilter/af_aformat.c @@ -111,6 +111,15 @@ static av_cold int init(AVFilterContext *ctx) return 0; } +static av_cold void uninit(AVFilterContext *ctx) +{ + AFormatContext *s = ctx->priv; + + ff_formats_unref(&s->formats); + ff_formats_unref(&s->sample_rates); + ff_channel_layouts_unref(&s->channel_layouts); +} + static int query_formats(AVFilterContext *ctx) { AFormatContext *s = ctx->priv; @@ -118,14 +127,18 @@ static int query_formats(AVFilterContext *ctx) ret = ff_set_common_formats(ctx, s->formats ? s->formats : ff_all_formats(AVMEDIA_TYPE_AUDIO)); + s->formats = NULL; if (ret < 0) return ret; ret = ff_set_common_samplerates(ctx, s->sample_rates ? s->sample_rates : ff_all_samplerates()); + s->sample_rates = NULL; if (ret < 0) return ret; - return ff_set_common_channel_layouts(ctx, s->channel_layouts ? s->channel_layouts : + ret = ff_set_common_channel_layouts(ctx, s->channel_layouts ? s->channel_layouts : ff_all_channel_counts()); + s->channel_layouts = NULL; + return ret; } static const AVFilterPad avfilter_af_aformat_inputs[] = { @@ -148,6 +161,7 @@ AVFilter ff_af_aformat = { .name = "aformat", .description = NULL_IF_CONFIG_SMALL("Convert the input audio to one of the specified formats."), .init = init, + .uninit = uninit, .query_formats = query_formats, .priv_size = sizeof(AFormatContext), .priv_class = &aformat_class, From patchwork Wed Aug 12 20:49:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21614 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 B623C449720 for ; Wed, 12 Aug 2020 23:49:58 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6C47168B507; Wed, 12 Aug 2020 23:49:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 41F6568AE6F for ; Wed, 12 Aug 2020 23:49:52 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id t14so3170082wmi.3 for ; Wed, 12 Aug 2020 13:49:52 -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=UdmP30nJJAWBkzs+9cCvjMgiXG4fjrY7dHkAHIsDQ0k=; b=YLgzUgG1IVKKJshHWPqO8HwNQIT+K0vcTtyO1qHcZ3DwObqyLnlX1E33YmhdoWTcVP UghaR2UilS/AdcgIyoQZWtst5l54k+d6mMHdPPMXgZijQTXn0OWyiZWmSx5K1AH6tqxv bq6mP3KwadTDFTXCVqUKmAL29y1bfUY9U6kxHHGXDB13L7IiqnCq5trnIPMmCi/XTMDw Hx8x+vO9El5oKDxLabnB/4FIM76pYUwlhnzAPilgucB+BiWZXfv7TKeJq7BcMpcRuRic WQV1ZzudazmqKPSoMsMs33i3NjfAXz6E9A7jeMMaQV7Dgbxwd0JR+XVW8EPWwZrywQdK parA== 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=UdmP30nJJAWBkzs+9cCvjMgiXG4fjrY7dHkAHIsDQ0k=; b=LK8qaXBjv7yMtlpR0J0YATuJVzJJT81kmKBcmzm6OnTWmIsqmxf0Nh6+FWG5Mpy/ns aYzUFJzjY1loyXLY0V7gB3VqgkloGb/Wh5BJVYKgiIl+30nvZYfFkzKYoOj/dgdahHFG +t6b7MlMJMmn6ScsiBQzuxyvuMqhn9t/kSqAmuxuw3WAqqXyktJdB84aKyTZFi5HclOW L5h2auyCOoJxuvwPaxpRDMXeROrjk3cheaJLTl/Ojp0IUe4n6Xu/V3aVCXkOOBH8BsFb 4BempJwRjAjEHXueB19rYG/I7Wa4W6TtHDrQcpq2YE+KqUYaHVNWUK/Rw1HUib+oKeds dLzA== X-Gm-Message-State: AOAM531ZdKenoXCSmzkvpv/yZHdZXOvmMA/0XTAxG2YBpDx8WV7sxoNK 7cPjxfFO5NMIIdXM5I/HKf9ZgEk8 X-Google-Smtp-Source: ABdhPJwsvQ0WsdbILoH2SUsY24K/ywBMuaKapsrUnJtaiBfejwQdwfKR+zyweE10E09DRcHH0JExnw== X-Received: by 2002:a05:600c:224e:: with SMTP id a14mr1344832wmm.80.1597265391300; Wed, 12 Aug 2020 13:49:51 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id s19sm7131145wrb.54.2020.08.12.13.49.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Aug 2020 13:49:50 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Aug 2020 22:49:40 +0200 Message-Id: <20200812204940.32100-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200808140202.586-1-andreas.rheinhardt@gmail.com> References: <20200808140202.586-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/22] avfilter/formats: Avoid allocations when merging channel layouts 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" When one merges two AVFilterChannelLayouts structs, there is no need to allocate a new one. Instead one can reuse one of the two given ones. If one does this, one also doesn't need to update the references of the AVFilterChannelLayouts that is reused. Therefore this commit reuses the structure with the higher refcount. Signed-off-by: Andreas Rheinhardt --- This can of course be applied independently of 7-21. libavfilter/formats.c | 48 +++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 00d050e439..2d33dd7afe 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -48,13 +48,13 @@ do { \ av_freep(&a); \ } while (0) -#define MERGE_REF(ret, a, fmts, type, fail) \ +#define MERGE_REF(ret, a, fmts, type, fail_statement) \ do { \ type ***tmp; \ \ if (!(tmp = av_realloc_array(ret->refs, ret->refcount + a->refcount, \ sizeof(*tmp)))) \ - goto fail; \ + { fail_statement } \ ret->refs = tmp; \ MERGE_REF_NO_ALLOC(ret, a, fmts); \ } while (0) @@ -157,10 +157,10 @@ AVFilterFormats *ff_merge_samplerates(AVFilterFormats *a, if (a->nb_formats && b->nb_formats) { MERGE_FORMATS(ret, a, b, formats, nb_formats, AVFilterFormats, fail); } else if (a->nb_formats) { - MERGE_REF(a, b, formats, AVFilterFormats, fail); + MERGE_REF(a, b, formats, AVFilterFormats, return NULL;); ret = a; } else { - MERGE_REF(b, a, formats, AVFilterFormats, fail); + MERGE_REF(b, a, formats, AVFilterFormats, return NULL;); ret = b; } @@ -177,7 +177,7 @@ fail: AVFilterChannelLayouts *ff_merge_channel_layouts(AVFilterChannelLayouts *a, AVFilterChannelLayouts *b) { - AVFilterChannelLayouts *ret = NULL; + uint64_t *channel_layouts; unsigned a_all = a->all_layouts + a->all_counts; unsigned b_all = b->all_layouts + b->all_counts; int ret_max, ret_nb = 0, i, j, round; @@ -201,15 +201,13 @@ AVFilterChannelLayouts *ff_merge_channel_layouts(AVFilterChannelLayouts *a, return NULL; b->nb_channel_layouts = j; } - MERGE_REF(b, a, channel_layouts, AVFilterChannelLayouts, fail); + MERGE_REF(b, a, channel_layouts, AVFilterChannelLayouts, return NULL;); return b; } ret_max = a->nb_channel_layouts + b->nb_channel_layouts; - if (!(ret = av_mallocz(sizeof(*ret))) || - !(ret->channel_layouts = av_malloc_array(ret_max, - sizeof(*ret->channel_layouts)))) - goto fail; + if (!(channel_layouts = av_malloc_array(ret_max, sizeof(channel_layouts)))) + return NULL; /* a[known] intersect b[known] */ for (i = 0; i < a->nb_channel_layouts; i++) { @@ -217,7 +215,7 @@ AVFilterChannelLayouts *ff_merge_channel_layouts(AVFilterChannelLayouts *a, continue; for (j = 0; j < b->nb_channel_layouts; j++) { if (a->channel_layouts[i] == b->channel_layouts[j]) { - ret->channel_layouts[ret_nb++] = a->channel_layouts[i]; + channel_layouts[ret_nb++] = a->channel_layouts[i]; a->channel_layouts[i] = b->channel_layouts[j] = 0; } } @@ -232,7 +230,7 @@ AVFilterChannelLayouts *ff_merge_channel_layouts(AVFilterChannelLayouts *a, bfmt = FF_COUNT2LAYOUT(av_get_channel_layout_nb_channels(fmt)); for (j = 0; j < b->nb_channel_layouts; j++) if (b->channel_layouts[j] == bfmt) - ret->channel_layouts[ret_nb++] = a->channel_layouts[i]; + channel_layouts[ret_nb++] = a->channel_layouts[i]; } /* 1st round: swap to prepare 2nd round; 2nd round: put it back */ FFSWAP(AVFilterChannelLayouts *, a, b); @@ -243,27 +241,23 @@ AVFilterChannelLayouts *ff_merge_channel_layouts(AVFilterChannelLayouts *a, continue; for (j = 0; j < b->nb_channel_layouts; j++) if (a->channel_layouts[i] == b->channel_layouts[j]) - ret->channel_layouts[ret_nb++] = a->channel_layouts[i]; + channel_layouts[ret_nb++] = a->channel_layouts[i]; } - ret->nb_channel_layouts = ret_nb; - if (!ret->nb_channel_layouts) + if (!ret_nb) goto fail; - ret->refs = av_realloc_array(NULL, a->refcount + b->refcount, - sizeof(*ret->refs)); - if (!ret->refs) - goto fail; - MERGE_REF_NO_ALLOC(ret, a, channel_layouts); - MERGE_REF_NO_ALLOC(ret, b, channel_layouts); - return ret; + if (a->refcount > b->refcount) + FFSWAP(AVFilterChannelLayouts *, a, b); + + MERGE_REF(b, a, channel_layouts, AVFilterChannelLayouts, goto fail;); + av_freep(&b->channel_layouts); + b->channel_layouts = channel_layouts; + b->nb_channel_layouts = ret_nb; + return b; fail: - if (ret) { - av_assert1(!ret->refs); - av_freep(&ret->channel_layouts); - av_freep(&ret); - } + av_free(channel_layouts); return NULL; }