From patchwork Fri Aug 21 20:44: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: 21805 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 4917C4499FE for ; Fri, 21 Aug 2020 23:44:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2279E68B69A; Fri, 21 Aug 2020 23:44:56 +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 4F9D9687F8D for ; Fri, 21 Aug 2020 23:44:50 +0300 (EEST) Received: by mail-ej1-f65.google.com with SMTP id u21so3274265ejz.0 for ; Fri, 21 Aug 2020 13:44:50 -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=0xeqm0LX1AKxyx7kBpr0RJkes11tahV4cKZsluf0c78=; b=JROpvqiBoJ/X9nTawxV3v7DK1NEhkDYtoM00UZ4Utr2mvXOPZLtZsBayNm1m7Mz9dR nqOLRfY0mNjrTTGsR6ZpaEX1iKaDu1i/8PuX9I57ZuuFLaAkpS3HWjVrd1Emk67Hn32+ IJD44uL5f6SGUUMTVhsGvViQIEMVihy3tJWtyEijwXKDu48EWTjBos1BKFOi9FQueIfe HQgtyps2w5aH2IoS2bv+GqGZXLzuM2yq/BXPH6LUalDvvcDnQlqO+gsHUS0TQ7DZyUJI eAGnu2ycQ3o5EvI42J/s+/URjrD/Zi9zNVsogTYV80uGQSmiYO5rixu6TgS8S2nMfct5 f01w== 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=0xeqm0LX1AKxyx7kBpr0RJkes11tahV4cKZsluf0c78=; b=MeIKL4QtfaHUBROF71KaSpI+oxjXMAWvVJZUheaZAYGgpbIx5iX3k2wo+ui5ykLMdL Cxeqfpo5Smvkn5iHbXOwaxaPOXTGmFSpiSubnMVgbiPoSSgMlmcjv/q+lg7nbWWt9rhh q98+ncqFtHm+TV3gcEmQ8J1Qm3owNwu2VznuT4Quy1SYr7qp7OaGhHphj3P/hQm2sEcI ySeKDYf/d/lZCSB4ODuEfIdSAJw9dJ6lJAxseFECI5vlovD4AcNrS+jaXlh44DdaVHet wtlv4AXxsZSrOPrOheYmxTwjYKFKCgQdGerMIhwCeWO6tzhm+mT7q1AYqbEB3pcu10Ym pBmw== X-Gm-Message-State: AOAM533ROqJQhdHrfld5mNqorQ0ufnNE72vGOPrWxGZBdM+YVdGBOCpQ t6bMJe5rqOJtxztm6gExkltRg9murgI= X-Google-Smtp-Source: ABdhPJy5Qcr12e3ni1pRuPgoA1QWNcSPwHD5+Q51a7X81ma38bzw2JnWLsQEKGS6NGMVJnSgGv2l1g== X-Received: by 2002:a17:906:8286:: with SMTP id h6mr4420527ejx.341.1598042689328; Fri, 21 Aug 2020 13:44:49 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id o15sm1682798edr.67.2020.08.21.13.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 13:44:48 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 21 Aug 2020 22:44:40 +0200 Message-Id: <20200821204440.28769-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200809155748.30092-12-andreas.rheinhardt@gmail.com> References: <20200809155748.30092-12-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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" If adding the list of input formats to its AVFilterLink fails, the list of output formats (which has not been attached to permanent storage yet) leaks. This has been fixed by not creating the lists of in- and output formats simultaneously. Instead creating said lists is relegated to ff_formats_pixdesc_filter() (this also avoids the reallocations implicit in using ff_add_format()) and the second list is only created after (and if) the first list has been permanently attached to ist AVFilterLink. Signed-off-by: Andreas Rheinhardt --- ff_formats_pixdesc_filter() uses av_pix_fmt_desc_get() under the hood; but both av_pix_fmt_desc_get() and av_pix_fmt_desc_next() lead (currently) to the same order of pixel formats (it coincides with the natural order) and given that this filter doesn't seem to have any preferred order at all, it wouldn't even matter if these two methods yielded different results one day. libavfilter/vf_hwdownload.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/libavfilter/vf_hwdownload.c b/libavfilter/vf_hwdownload.c index 33af30cf40..faf2ea8c0e 100644 --- a/libavfilter/vf_hwdownload.c +++ b/libavfilter/vf_hwdownload.c @@ -37,26 +37,13 @@ typedef struct HWDownloadContext { static int hwdownload_query_formats(AVFilterContext *avctx) { - AVFilterFormats *infmts = NULL; - AVFilterFormats *outfmts = NULL; - const AVPixFmtDescriptor *desc; + AVFilterFormats *fmts; int err; - for (desc = av_pix_fmt_desc_next(NULL); desc; - desc = av_pix_fmt_desc_next(desc)) { - if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) - err = ff_add_format(&infmts, av_pix_fmt_desc_get_id(desc)); - else - err = ff_add_format(&outfmts, av_pix_fmt_desc_get_id(desc)); - if (err) { - ff_formats_unref(&infmts); - ff_formats_unref(&outfmts); - return err; - } - } - - 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_pixdesc_filter(&fmts, AV_PIX_FMT_FLAG_HWACCEL, 0)) || + (err = ff_formats_ref(fmts, &avctx->inputs[0]->out_formats)) || + (err = ff_formats_pixdesc_filter(&fmts, 0, AV_PIX_FMT_FLAG_HWACCEL)) || + (err = ff_formats_ref(fmts, &avctx->outputs[0]->in_formats))) return err; return 0;