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.
Unified · Split
| @@ -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; | 385 | cleanup: |
| 386 | av_free(h[longer]); | ||
| 387 | return ret; | ||
| 384 | } | 388 | } |
| 385 | 389 | ||
| 386 | static av_cold void uninit(AVFilterContext *ctx) | 390 | static av_cold void uninit(AVFilterContext *ctx) |