diff mbox series

[FFmpeg-devel,21/21] avfilter/af_aformat: Add uninit function

Message ID 20200809155748.30092-15-andreas.rheinhardt@gmail.com
State Accepted
Commit a7bd37927628df3672488e07f718b3549bea717d
Headers show
Series [FFmpeg-devel,1/6] avfilter/formats: Remove ff_make_formatu64_list()
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Aug. 9, 2020, 3:57 p.m. UTC
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 <andreas.rheinhardt@gmail.com>
---
 libavfilter/af_aformat.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Nicolas George Aug. 9, 2020, 4:48 p.m. UTC | #1
Andreas Rheinhardt (12020-08-09):
> 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 <andreas.rheinhardt@gmail.com>
> ---
>  libavfilter/af_aformat.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)

LGTM.

Regards,
diff mbox series

Patch

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,