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
329 SincContext *s = ctx->priv;329 SincContext *s = ctx->priv;
330 float Fn = s->sample_rate * .5f;330 float Fn = s->sample_rate * .5f;
331 float *h[2];331 float *h[2];
332 int i, n, post_peak, longer;332 int i, n, post_peak, longer, ret;
333 333
334 outlink->sample_rate = s->sample_rate;334 outlink->sample_rate = s->sample_rate;
335 s->pts = 0;335 s->pts = 0;
@@ -360,9 +360,9 @@ static int config_output(AVFilterLink *outlink) · 24 unmodified lines
360 }360 }
361 361
362 if (s->phase != 50.f) {362 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);
364 if (ret < 0)364 if (ret < 0)
365 return ret;365 goto cleanup;
366 } else {366 } else {
367 post_peak = n >> 1;367 post_peak = n >> 1;
368 }368 }
@@ -370,17 +370,21 @@ static int config_output(AVFilterLink *outlink) · 1 unmodified line
370 s->n = 1 << (av_log2(n) + 1);370 s->n = 1 << (av_log2(n) + 1);
371 s->rdft_len = 1 << av_log2(n);371 s->rdft_len = 1 << av_log2(n);
372 s->coeffs = av_calloc(s->n, sizeof(*s->coeffs));372 s->coeffs = av_calloc(s->n, sizeof(*s->coeffs));
373 if (!s->coeffs)373 if (!s->coeffs) {
374 return AVERROR(ENOMEM);374 ret = AVERROR(ENOMEM);
375 goto cleanup;
376 }
375 377
376 for (i = 0; i < n; i++)378 for (i = 0; i < n; i++)
377 s->coeffs[i] = h[longer][i];379 s->coeffs[i] = h[longer][i];
378 av_free(h[longer]);
379 380
380 av_tx_uninit(&s->tx);381 av_tx_uninit(&s->tx);
381 av_tx_uninit(&s->itx);382 av_tx_uninit(&s->itx);
383 ret = 0;
382 384
383 return 0;385cleanup:
386 av_free(h[longer]);
387 return ret;
384}388}
385 389
386static av_cold void uninit(AVFilterContext *ctx)390static 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