mirror of
https://gitee.com/openharmony/third_party_ffmpeg
synced 2024-11-27 05:00:37 +00:00
avfilter/asrc_sinc: Don't allocate arrays separately
Besides the obvious advantages this also fixes a potential memleak: If only one of the arrays had been successfully allocated, the other would leak. This also fixes Coverity issues #1440386 and #1440387. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
parent
febd37f4bd
commit
ab39f0d841
@ -227,10 +227,11 @@ static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, floa
|
|||||||
|
|
||||||
for (i = *len, work_len = 2 * 2 * 8; i > 1; work_len <<= 1, i >>= 1);
|
for (i = *len, work_len = 2 * 2 * 8; i > 1; work_len <<= 1, i >>= 1);
|
||||||
|
|
||||||
work = av_calloc(work_len + 2, sizeof(*work)); /* +2: (UN)PACK */
|
/* The first part is for work (+2 for (UN)PACK), the latter for pi_wraps. */
|
||||||
pi_wraps = av_calloc(((work_len + 2) / 2), sizeof(*pi_wraps));
|
work = av_calloc((work_len + 2) + (work_len / 2 + 1), sizeof(float));
|
||||||
if (!work || !pi_wraps)
|
if (!work)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
pi_wraps = &work[work_len + 2];
|
||||||
|
|
||||||
memcpy(work, *h, *len * sizeof(*work));
|
memcpy(work, *h, *len * sizeof(*work));
|
||||||
|
|
||||||
@ -240,7 +241,6 @@ static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, floa
|
|||||||
s->rdft = av_rdft_init(av_log2(work_len), DFT_R2C);
|
s->rdft = av_rdft_init(av_log2(work_len), DFT_R2C);
|
||||||
s->irdft = av_rdft_init(av_log2(work_len), IDFT_C2R);
|
s->irdft = av_rdft_init(av_log2(work_len), IDFT_C2R);
|
||||||
if (!s->rdft || !s->irdft) {
|
if (!s->rdft || !s->irdft) {
|
||||||
av_free(pi_wraps);
|
|
||||||
av_free(work);
|
av_free(work);
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
}
|
}
|
||||||
@ -323,7 +323,6 @@ static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, floa
|
|||||||
*len = end - begin;
|
*len = end - begin;
|
||||||
*h = av_realloc_f(*h, *len, sizeof(**h));
|
*h = av_realloc_f(*h, *len, sizeof(**h));
|
||||||
if (!*h) {
|
if (!*h) {
|
||||||
av_free(pi_wraps);
|
|
||||||
av_free(work);
|
av_free(work);
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
}
|
}
|
||||||
@ -338,7 +337,6 @@ static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, floa
|
|||||||
work_len, pi_wraps[work_len >> 1] / M_PI, peak, peak_imp_sum, imp_peak,
|
work_len, pi_wraps[work_len >> 1] / M_PI, peak, peak_imp_sum, imp_peak,
|
||||||
work[imp_peak], *len, *post_len, 100.f - 100.f * *post_len / (*len - 1));
|
work[imp_peak], *len, *post_len, 100.f - 100.f * *post_len / (*len - 1));
|
||||||
|
|
||||||
av_free(pi_wraps);
|
|
||||||
av_free(work);
|
av_free(work);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user