And make sure uninit is always called on failure.
---
libavfilter/af_compand.c | 54 +++++++++++++++++++++++++-----------------------
1 file changed, 28 insertions(+), 26 deletions(-)
diff --git a/libavfilter/af_compand.c b/libavfilter/af_compand.c
index 15202f3..38dd454 100644
--- a/libavfilter/af_compand.c
+++ b/libavfilter/af_compand.c
@@ -344,6 +344,8 @@ static int config_output(AVFilterLink *outlink)
count_items(s->decays, &nb_decays);
count_items(s->points, &nb_points);
+ uninit(ctx);
+
if (channels <= 0) {
av_log(ctx, AV_LOG_ERROR, "Invalid number of channels: %d\n",
channels);
return AVERROR(EINVAL);
@@ -355,31 +357,29 @@ static int config_output(AVFilterLink *outlink)
return AVERROR(EINVAL);
}
- uninit(ctx);
-
s->nb_channels = channels;
s->channels = av_mallocz_array(channels, sizeof(*s->channels));
s->nb_segments = (nb_points + 4) * 2;
s->segments = av_mallocz_array(s->nb_segments, sizeof(*s->segments));
if (!s->channels || !s->segments) {
- uninit(ctx);
- return AVERROR(ENOMEM);
+ err = AVERROR(ENOMEM);
+ goto fail;
}
p = s->attacks;
for (i = 0, new_nb_items = 0; i < nb_attacks; i++) {
char *tstr = av_get_token(&p, "|");
if (!tstr) {
- uninit(ctx);
- return AVERROR(ENOMEM);
+ err = AVERROR(ENOMEM);
+ goto fail;
}
new_nb_items += sscanf(tstr, "%f", &s->channels[i].attack) == 1;
av_freep(&tstr);
if (s->channels[i].attack < 0) {
- uninit(ctx);
- return AVERROR(EINVAL);
+ err = AVERROR(EINVAL);
+ goto fail;
}
if (*p)
p++;
@@ -390,14 +390,14 @@ static int config_output(AVFilterLink *outlink)
for (i = 0, new_nb_items = 0; i < nb_decays; i++) {
char *tstr = av_get_token(&p, "|");
if (!tstr) {
- uninit(ctx);
- return AVERROR(ENOMEM);
+ err = AVERROR(ENOMEM);
+ goto fail;
}
new_nb_items += sscanf(tstr, "%f", &s->channels[i].decay) == 1;
av_freep(&tstr);
if (s->channels[i].decay < 0) {
- uninit(ctx);
- return AVERROR(EINVAL);
+ err = AVERROR(EINVAL);
+ goto fail;
}
if (*p)
p++;
@@ -408,8 +408,8 @@ static int config_output(AVFilterLink *outlink)
av_log(ctx, AV_LOG_ERROR,
"Number of attacks %d differs from number of decays %d.\n",
nb_attacks, nb_decays);
- uninit(ctx);
- return AVERROR(EINVAL);
+ err = AVERROR(EINVAL);
+ goto fail;
}
#define S(x) s->segments[2 * ((x) + 1)]
@@ -417,8 +417,8 @@ static int config_output(AVFilterLink *outlink)
for (i = 0, new_nb_items = 0; i < nb_points; i++) {
char *tstr = av_get_token(&p, "|");
if (!tstr) {
- uninit(ctx);
- return AVERROR(ENOMEM);
+ err = AVERROR(ENOMEM);
+ goto fail;
}
err = sscanf(tstr, "%f/%f", &S(i).x, &S(i).y);
@@ -426,14 +426,14 @@ static int config_output(AVFilterLink *outlink)
if (err != 2) {
av_log(ctx, AV_LOG_ERROR,
"Invalid and/or missing input/output value.\n");
- uninit(ctx);
- return AVERROR(EINVAL);
+ err = AVERROR(EINVAL);
+ goto fail;
}
if (i && S(i - 1).x > S(i).x) {
av_log(ctx, AV_LOG_ERROR,
"Transfer function input values must be increasing.\n");
- uninit(ctx);
- return AVERROR(EINVAL);
+ err = AVERROR(EINVAL);
+ goto fail;
}
S(i).y -= S(i).x;
av_log(ctx, AV_LOG_DEBUG, "%d: x=%f y=%f\n", i, S(i).x, S(i).y);
@@ -537,8 +537,8 @@ static int config_output(AVFilterLink *outlink)
s->delay_frame = av_frame_alloc();
if (!s->delay_frame) {
- uninit(ctx);
- return AVERROR(ENOMEM);
+ err = AVERROR(ENOMEM);
+ goto fail;
}
s->delay_frame->format = outlink->format;
@@ -546,13 +546,15 @@ static int config_output(AVFilterLink *outlink)
s->delay_frame->channel_layout = outlink->channel_layout;
err = av_frame_get_buffer(s->delay_frame, 32);
- if (err) {
- uninit(ctx);
- return err;
- }
+ if (err)
+ goto fail;
s->compand = compand_delay;
return 0;
+
+fail:
+ uninit(ctx);
+ return err;
}
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
--
1.8.5.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel