1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

avcodec/resample: check for malloc failure

Found-by: CSA
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2014-07-31 13:04:28 +02:00
parent 72555f4a38
commit ceff29b9ad

View File

@ -348,9 +348,16 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl
/* XXX: move those malloc to resample init code */ /* XXX: move those malloc to resample init code */
for (i = 0; i < s->filter_channels; i++) { for (i = 0; i < s->filter_channels; i++) {
bufin[i] = av_malloc_array((nb_samples + s->temp_len), sizeof(short)); bufin[i] = av_malloc_array((nb_samples + s->temp_len), sizeof(short));
bufout[i] = av_malloc_array(lenout, sizeof(short));
if (!bufin[i] || !bufout[i]) {
av_log(s->resample_context, AV_LOG_ERROR, "Could not allocate buffer\n");
nb_samples1 = 0;
goto fail;
}
memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short)); memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short));
buftmp2[i] = bufin[i] + s->temp_len; buftmp2[i] = bufin[i] + s->temp_len;
bufout[i] = av_malloc_array(lenout, sizeof(short));
} }
if (s->input_channels == 2 && s->output_channels == 1) { if (s->input_channels == 2 && s->output_channels == 1) {
@ -411,6 +418,7 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl
} }
} }
fail:
for (i = 0; i < s->filter_channels; i++) { for (i = 0; i < s->filter_channels; i++) {
av_free(bufin[i]); av_free(bufin[i]);
av_free(bufout[i]); av_free(bufout[i]);