[FFmpeg-cvslog] swresample/swresample: Cleanup on init failure.

Michael Niedermayer git at videolan.org
Wed Jun 17 22:09:33 CEST 2015


ffmpeg | branch: release/2.2 | Michael Niedermayer <michaelni at gmx.at> | Thu Jun  4 03:47:55 2015 +0200| [b97fb80db9e6a185aad432ef57eb6b9598e322bf] | committer: Michael Niedermayer

swresample/swresample: Cleanup on init failure.

This avoids leaks if the user doest call swr_close() after a failed init

Found-by: James Almer <jamrial at gmail.com>
Reviewed-by: James Almer <jamrial at gmail.com>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
(cherry picked from commit c3f87f7545d42520921bc448b9fbd7324c574e49)

Conflicts:

	libswresample/swresample.c

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b97fb80db9e6a185aad432ef57eb6b9598e322bf
---

 libswresample/swresample.c |   28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 5b9dc7c..68c53e6 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -363,7 +363,8 @@ av_cold int swr_init(struct SwrContext *s){
         && s->int_sample_fmt != AV_SAMPLE_FMT_DBLP
         && s->resample){
         av_log(s, AV_LOG_ERROR, "Resampling only supported with internal s16/s32/flt/dbl\n");
-        return -1;
+        ret = AVERROR(EINVAL);
+        goto fail;
     }
 
 #define RSC 1 //FIXME finetune
@@ -377,7 +378,8 @@ av_cold int swr_init(struct SwrContext *s){
     if(!s-> in.ch_count){
         av_assert0(!s->in_ch_layout);
         av_log(s, AV_LOG_ERROR, "Input channel count and layout are unset\n");
-        return -1;
+        ret = AVERROR(EINVAL);
+        goto fail;
     }
 
     if ((!s->out_ch_layout || !s->in_ch_layout) && s->used_ch_count != s->out.ch_count && !s->rematrix_custom) {
@@ -386,7 +388,8 @@ av_cold int swr_init(struct SwrContext *s){
         av_get_channel_layout_string(l2, sizeof(l2), s->out.ch_count, s->out_ch_layout);
         av_log(s, AV_LOG_ERROR, "Rematrix is needed between %s and %s "
                "but there is not enough information to do it\n", l1, l2);
-        return -1;
+        ret = AVERROR(EINVAL);
+        goto fail;
     }
 
 av_assert0(s->used_ch_count);
@@ -408,8 +411,10 @@ av_assert0(s->out.ch_count);
     s->out_convert= swri_audio_convert_alloc(s->out_sample_fmt,
                                              s->int_sample_fmt, s->out.ch_count, NULL, 0);
 
-    if (!s->in_convert || !s->out_convert)
-        return AVERROR(ENOMEM);
+    if (!s->in_convert || !s->out_convert) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
 
     s->postin= s->in;
     s->preout= s->out;
@@ -436,12 +441,19 @@ av_assert0(s->out.ch_count);
     }
 
     if ((ret = swri_dither_init(s, s->out_sample_fmt, s->int_sample_fmt)) < 0)
-        return ret;
+        goto fail;
 
-    if(s->rematrix || s->dither.method)
-        return swri_rematrix_init(s);
+    if(s->rematrix || s->dither.method) {
+        ret = swri_rematrix_init(s);
+        if (ret < 0)
+            goto fail;
+    }
 
     return 0;
+fail:
+    clear_context(s);
+    return ret;
+
 }
 
 int swri_realloc_audio(AudioData *a, int count){



More information about the ffmpeg-cvslog mailing list