From 78f60f058415e24fe33417d3dbe3b39f4279208b Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 11 Aug 2015 11:30:52 -0700 Subject: [PATCH] Fix regressions: segfaults during/after conversion * segfault when resampling audio av_samples_alloc allocates the *samples* but not the *array* that takes the pointers to the samples. Have to allocate that ourselves. This broke MediaWiki .ogv generation when doing audio resampling. * segfault at end from mistaken free of bogus sw_ctx sw_ctx was never initialized in some cases, and we checked it against NULL and tried to clear it, causing a segfault. This broke MediaWiki .ogv generation from WebM VP9 sources. --- src/ffmpeg2theora.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ffmpeg2theora.c b/src/ffmpeg2theora.c index 67ec3bd..ff9d651 100644 --- a/src/ffmpeg2theora.c +++ b/src/ffmpeg2theora.c @@ -543,7 +543,7 @@ void ff2theora_output(ff2theora this) { int synced = this->start_time == 0.0; AVRational display_aspect_ratio, sample_aspect_ratio; - struct SwrContext *swr_ctx; + struct SwrContext *swr_ctx = NULL; uint8_t **dst_audio_data = NULL; int dst_linesize; int src_nb_samples = 1024, dst_nb_samples, max_dst_nb_samples; @@ -997,6 +997,7 @@ void ff2theora_output(ff2theora this) { max_dst_nb_samples = dst_nb_samples = av_rescale_rnd(src_nb_samples, this->sample_rate, sample_rate, AV_ROUND_UP); + dst_audio_data = malloc((sizeof (uint8_t *)) * this->channels); if (av_samples_alloc(dst_audio_data, &dst_linesize, this->channels, dst_nb_samples, AV_SAMPLE_FMT_FLTP, 0) < 0) { fprintf(stderr, "Could not allocate destination samples\n"); @@ -1825,8 +1826,11 @@ void ff2theora_output(ff2theora this) { frame_dealloc(output_cropped_p); frame_dealloc(output_padded_p); } - if (dst_audio_data) + if (dst_audio_data) { av_freep(&dst_audio_data[0]); + free(dst_audio_data); + dst_audio_data = NULL; + } av_freep(&dst_audio_data); if(swr_ctx) { swr_close(swr_ctx); -- 2.5.0