[FFmpeg-cvslog] avformat/libquvi: fix error handling

Gilles Chanteperdrix git at videolan.org
Sun May 31 19:18:20 CEST 2015


ffmpeg | branch: master | Gilles Chanteperdrix <gilles.chanteperdrix at xenomai.org> | Wed Apr  8 19:16:36 2015 +0200| [d61386a69002be2cff212b03b51411dd294a7a22] | committer: Michael Niedermayer

avformat/libquvi: fix error handling

avoid calling cleanup functions on uninitialized variables

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavformat/libquvi.c |   46 +++++++++++++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/libavformat/libquvi.c b/libavformat/libquvi.c
index 7c5f7a2..7151694 100644
--- a/libavformat/libquvi.c
+++ b/libavformat/libquvi.c
@@ -63,28 +63,41 @@ static int libquvi_read_header(AVFormatContext *s)
     char *media_url, *pagetitle;
 
     rc = quvi_init(&q);
-    if (rc != QUVI_OK)
-        goto quvi_fail;
+    if (rc != QUVI_OK) {
+        av_log(s, AV_LOG_ERROR, "%s\n", quvi_strerror(q, rc));
+        return AVERROR_EXTERNAL;
+    }
 
     quvi_setopt(q, QUVIOPT_FORMAT, qc->format);
 
     rc = quvi_parse(q, s->filename, &m);
-    if (rc != QUVI_OK)
-        goto quvi_fail;
+    if (rc != QUVI_OK) {
+        av_log(s, AV_LOG_ERROR, "%s\n", quvi_strerror(q, rc));
+        ret = AVERROR_EXTERNAL;
+        goto err_quvi_close;
+    }
 
     rc = quvi_getprop(m, QUVIPROP_MEDIAURL, &media_url);
-    if (rc != QUVI_OK)
-        goto quvi_fail;
+    if (rc != QUVI_OK) {
+        av_log(s, AV_LOG_ERROR, "%s\n", quvi_strerror(q, rc));
+        ret = AVERROR_EXTERNAL;
+        goto err_quvi_cleanup;
+    }
 
-    if (!(qc->fmtctx = avformat_alloc_context()))
-            goto quvi_fail;
+    if (!(qc->fmtctx = avformat_alloc_context())) {
+        ret = AVERROR(ENOMEM);
+        goto err_quvi_cleanup;
+    }
 
-    if ((ret = ff_copy_whitelists(qc->fmtctx, s)) < 0)
-        goto end;
+    if ((ret = ff_copy_whitelists(qc->fmtctx, s)) < 0) {
+        avformat_free_context(qc->fmtctx);
+        qc->fmtctx = NULL;
+        goto err_quvi_cleanup;
+    }
 
     ret = avformat_open_input(&qc->fmtctx, media_url, NULL, NULL);
     if (ret < 0)
-        goto end;
+        goto err_quvi_cleanup;
 
     rc = quvi_getprop(m, QUVIPROP_PAGETITLE, &pagetitle);
     if (rc == QUVI_OK)
@@ -95,7 +108,7 @@ static int libquvi_read_header(AVFormatContext *s)
         AVStream *ist = qc->fmtctx->streams[i];
         if (!st) {
             ret = AVERROR(ENOMEM);
-            goto end;
+            goto err_close_input;
         }
         avpriv_set_pts_info(st, ist->pts_wrap_bits, ist->time_base.num, ist->time_base.den);
         avcodec_copy_context(st->codec, qc->fmtctx->streams[i]->codec);
@@ -103,12 +116,11 @@ static int libquvi_read_header(AVFormatContext *s)
 
     return 0;
 
-quvi_fail:
-    av_log(s, AV_LOG_ERROR, "%s\n", quvi_strerror(q, rc));
-    ret = AVERROR_EXTERNAL;
-
-end:
+  err_close_input:
+    avformat_close_input(&qc->fmtctx);
+  err_quvi_cleanup:
     quvi_parse_close(&m);
+  err_quvi_close:
     quvi_close(&q);
     return ret;
 }



More information about the ffmpeg-cvslog mailing list