History

avfilter/af_aformat: Add uninit function

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.

Andreas Rheinhardt committed 6 years ago

Commit a7bd3791 parent eaa6c081 file · +15 −1Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_aformat.c+15−1
@@ -111,6 +111,15 @@ static av_cold int init(AVFilterContext *ctx) · 110 unmodified lines
111111 return 0;
112112 }
113113
114+static av_cold void uninit(AVFilterContext *ctx)
115+{
116+ AFormatContext *s = ctx->priv;
117+
118+ ff_formats_unref(&s->formats);
119+ ff_formats_unref(&s->sample_rates);
120+ ff_channel_layouts_unref(&s->channel_layouts);
121+}
122+
114123 static int query_formats(AVFilterContext *ctx)
115124 {
116125 AFormatContext *s = ctx->priv;
@@ -118,14 +127,18 @@ static int query_formats(AVFilterContext *ctx) · 1 unmodified line
118127
119128 ret = ff_set_common_formats(ctx, s->formats ? s->formats :
120129 ff_all_formats(AVMEDIA_TYPE_AUDIO));
130+ s->formats = NULL;
121131 if (ret < 0)
122132 return ret;
123133 ret = ff_set_common_samplerates(ctx, s->sample_rates ? s->sample_rates :
124134 ff_all_samplerates());
135+ s->sample_rates = NULL;
125136 if (ret < 0)
126137 return ret;
127− return ff_set_common_channel_layouts(ctx, s->channel_layouts ? s->channel_layouts :
138+ ret = ff_set_common_channel_layouts(ctx, s->channel_layouts ? s->channel_layouts :
128139 ff_all_channel_counts());
140+ s->channel_layouts = NULL;
141+ return ret;
129142 }
130143
131144 static const AVFilterPad avfilter_af_aformat_inputs[] = {
@@ -148,6 +161,7 @@ AVFilter ff_af_aformat = { · 16 unmodified lines
148161 .name = "aformat",
149162 .description = NULL_IF_CONFIG_SMALL("Convert the input audio to one of the specified formats."),
150163 .init = init,
164+ .uninit = uninit,
151165 .query_formats = query_formats,
152166 .priv_size = sizeof(AFormatContext),
153167 .priv_class = &aformat_class,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t