[FFmpeg-cvslog] segment: reorder seg_write_header allocation

Luca Barbato git at videolan.org
Sat Apr 28 21:10:21 CEST 2012


ffmpeg | branch: master | Luca Barbato <lu_zero at gentoo.org> | Fri Apr 27 11:09:30 2012 -0700| [3b52e9da10158029edbd01bafe2235e653e6eaec] | committer: Luca Barbato

segment: reorder seg_write_header allocation

As pointed by Paul B Mahol <onemda at gmail.com> the previous code could
lead to null pointer dereference.

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

 libavformat/segment.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/libavformat/segment.c b/libavformat/segment.c
index 1af412a..8274792 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -113,10 +113,15 @@ static int seg_write_header(AVFormatContext *s)
     seg->offset_time = 0;
     seg->recording_time = seg->time * 1000000;
 
+    oc = avformat_alloc_context();
+
+    if (!oc)
+        return AVERROR(ENOMEM);
+
     if (seg->list)
         if ((ret = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE,
                               &s->interrupt_callback, NULL)) < 0)
-            return ret;
+            goto fail;
 
     for (i = 0; i< s->nb_streams; i++)
         seg->has_video +=
@@ -127,13 +132,6 @@ static int seg_write_header(AVFormatContext *s)
                "More than a single video stream present, "
                "expect issues decoding it.\n");
 
-    oc = avformat_alloc_context();
-
-    if (!oc) {
-        ret = AVERROR(ENOMEM);
-        goto fail;
-    }
-
     oc->oformat = av_guess_format(seg->format, s->filename, NULL);
 
     if (!oc->oformat) {



More information about the ffmpeg-cvslog mailing list