summaryrefslogtreecommitdiff
path: root/libavfilter/vf_showpalette.c
diff options
context:
space:
mode:
authorGanesh Ajjanagadde <gajjanagadde@gmail.com>2015-12-04 01:46:07 -0500
committerGanesh Ajjanagadde <gajjanagadde@gmail.com>2015-12-09 07:57:37 -0500
commit00c322014904c2d5be92cc292b162d31f18a7058 (patch)
tree54310a1394e8859789f6d6fea85e67faace07102 /libavfilter/vf_showpalette.c
parentcb93df0dcbd34107c64ec053504fa294b728a9c9 (diff)
lavfi/show_palette: 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. Unfortunately, even leaving aside this subtle intermediate failure aspect, commit 8087632027d755cd32ccc9e91ea025e276197055 was only partially successful in addressing memleaks. Hopefully, this commit fixes the issue completely. Tested with valgrind --leak-check=full --show-leak-kinds=all, and manual simulation of malloc/realloc failures. Fixes: CID 1270818. Reviewed-by: Clément Bœsch <u@pkh.me> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
Diffstat (limited to 'libavfilter/vf_showpalette.c')
-rw-r--r--libavfilter/vf_showpalette.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/libavfilter/vf_showpalette.c b/libavfilter/vf_showpalette.c
index fcb43a35cb..f1627ba58e 100644
--- a/libavfilter/vf_showpalette.c
+++ b/libavfilter/vf_showpalette.c
@@ -50,14 +50,22 @@ static int query_formats(AVFilterContext *ctx)
AVFilterFormats *in = ff_make_format_list(in_fmts);
AVFilterFormats *out = ff_make_format_list(out_fmts);
if (!in || !out) {
- av_freep(&in);
- av_freep(&out);
- return AVERROR(ENOMEM);
+ ret = AVERROR(ENOMEM);
+ goto fail;
}
+
if ((ret = ff_formats_ref(in , &ctx->inputs[0]->out_formats)) < 0 ||
(ret = ff_formats_ref(out, &ctx->outputs[0]->in_formats)) < 0)
- return ret;
+ goto fail;
return 0;
+fail:
+ if (in)
+ av_freep(&in->formats);
+ av_freep(&in);
+ if (out)
+ av_freep(&out->formats);
+ av_freep(&out);
+ return ret;
}
static int config_output(AVFilterLink *outlink)