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