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,