summaryrefslogtreecommitdiff
path: root/libavfilter/af_amix.c
diff options
context:
space:
mode:
authorGanesh Ajjanagadde <gajjanagadde@gmail.com>2015-12-04 02:04:46 -0500
committerGanesh Ajjanagadde <gajjanagadde@gmail.com>2015-12-09 07:58:19 -0500
commit89bbf01978194ee1354bb3feef139a648bc1903b (patch)
tree5dffd270a08510dfa3d111f1ee63866b03b46b3e /libavfilter/af_amix.c
parent924fcac52148ef3e37ea39b5901299930b9c1b28 (diff)
lavfi/af_amix: fix memory leak
Recent commits 6aaac24d72a7da631173209841a3944fcb4a3309 and 3835554bf8ed78539a3492c239f979c0ab03a15f made progress towards cleaning up usage of the formats API, and in particular fixed possible NULL pointer dereferences. This commit addresses the issue of possible resource leaks when some intermediate call fails. Tested with valgrind --leak-check=full --show-leak-kinds=all, and manual simulation of malloc/realloc failures. Fixes: CID 1250334. Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
Diffstat (limited to 'libavfilter/af_amix.c')
-rw-r--r--libavfilter/af_amix.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c
index 223328bfff..e64e289108 100644
--- a/libavfilter/af_amix.c
+++ b/libavfilter/af_amix.c
@@ -519,20 +519,23 @@ static int query_formats(AVFilterContext *ctx)
int ret;
layouts = ff_all_channel_layouts();
- if (!layouts)
- return AVERROR(ENOMEM);
+ if (!layouts) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
- if ((ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLT)) < 0)
- return ret;
- if ((ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLTP)) < 0)
- return ret;
- ret = ff_set_common_formats(ctx, formats);
- if (ret < 0)
- return ret;
- ret = ff_set_common_channel_layouts(ctx, layouts);
- if (ret < 0)
- return ret;
- return ff_set_common_samplerates(ctx, ff_all_samplerates());
+ if ((ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLT )) < 0 ||
+ (ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLTP)) < 0 ||
+ (ret = ff_set_common_formats (ctx, formats)) < 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;
}
static const AVFilterPad avfilter_af_amix_outputs[] = {