segment: reorder seg_write_header allocation

As pointed by Paul B Mahol <onemda@gmail.com> the previous code could
lead to null pointer dereference.
This commit is contained in:
Luca Barbato 2012-04-27 11:09:30 -07:00
parent e1e146a2d1
commit 3b52e9da10

View File

@ -113,10 +113,15 @@ static int seg_write_header(AVFormatContext *s)
seg->offset_time = 0; seg->offset_time = 0;
seg->recording_time = seg->time * 1000000; seg->recording_time = seg->time * 1000000;
oc = avformat_alloc_context();
if (!oc)
return AVERROR(ENOMEM);
if (seg->list) if (seg->list)
if ((ret = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE, if ((ret = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE,
&s->interrupt_callback, NULL)) < 0) &s->interrupt_callback, NULL)) < 0)
return ret; goto fail;
for (i = 0; i< s->nb_streams; i++) for (i = 0; i< s->nb_streams; i++)
seg->has_video += seg->has_video +=
@ -127,13 +132,6 @@ static int seg_write_header(AVFormatContext *s)
"More than a single video stream present, " "More than a single video stream present, "
"expect issues decoding it.\n"); "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); oc->oformat = av_guess_format(seg->format, s->filename, NULL);
if (!oc->oformat) { if (!oc->oformat) {