History

avfilter/asrc_sinc: fix leak in config_input()

In config_input(), fir_to_phase() allocates memory in h[longer], which would leak if av_calloc() to s->coeffs failed. lpf() allocates memory in h[0] and h[1], which would leak if fir_to_phase() failed. To fix this leak, add av_free(h[longer]) in as cleanup code, and replace return AVERROR* with goto cleanup to prevent from leaks.

Lidong Yan committed 1 year ago

Commit a4a71b51 parent 5f62e2d1 file · +11 −7Browse files

Unified · Split

libavfilter/asrc_sinc.c+11−7
@@ -329,7 +329,7 @@ static int config_output(AVFilterLink *outlink) · 328 unmodified lines
329329 SincContext *s = ctx->priv;
330330 float Fn = s->sample_rate * .5f;
331331 float *h[2];
332− int i, n, post_peak, longer;
332+ int i, n, post_peak, longer, ret;
333333
334334 outlink->sample_rate = s->sample_rate;
335335 s->pts = 0;
@@ -360,9 +360,9 @@ static int config_output(AVFilterLink *outlink) · 24 unmodified lines
360360 }
361361
362362 if (s->phase != 50.f) {
363− int ret = fir_to_phase(s, &h[longer], &n, &post_peak, s->phase);
363+ ret = fir_to_phase(s, &h[longer], &n, &post_peak, s->phase);
364364 if (ret < 0)
365− return ret;
365+ goto cleanup;
366366 } else {
367367 post_peak = n >> 1;
368368 }
@@ -370,17 +370,21 @@ static int config_output(AVFilterLink *outlink) · 1 unmodified line
370370 s->n = 1 << (av_log2(n) + 1);
371371 s->rdft_len = 1 << av_log2(n);
372372 s->coeffs = av_calloc(s->n, sizeof(*s->coeffs));
373− if (!s->coeffs)
374− return AVERROR(ENOMEM);
373+ if (!s->coeffs) {
374+ ret = AVERROR(ENOMEM);
375+ goto cleanup;
376+ }
375377
376378 for (i = 0; i < n; i++)
377379 s->coeffs[i] = h[longer][i];
378− av_free(h[longer]);
379380
380381 av_tx_uninit(&s->tx);
381382 av_tx_uninit(&s->itx);
383+ ret = 0;
382384
383− return 0;
385+cleanup:
386+ av_free(h[longer]);
387+ return ret;
384388 }
385389
386390 static av_cold void uninit(AVFilterContext *ctx)

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