Commit ccafd472 authored by Baptiste Coudurier's avatar Baptiste Coudurier

factorize read_header failure freeing code

Originally committed as revision 13837 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 6919e54c
...@@ -156,7 +156,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -156,7 +156,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
get_guid(pb, &g); get_guid(pb, &g);
if (memcmp(&g, &asf_header, sizeof(GUID))) if (memcmp(&g, &asf_header, sizeof(GUID)))
goto fail; return -1;
get_le64(pb); get_le64(pb);
get_le32(pb); get_le32(pb);
get_byte(pb); get_byte(pb);
...@@ -181,7 +181,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -181,7 +181,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
break; break;
} }
if (gsize < 24) if (gsize < 24)
goto fail; return -1;
if (!memcmp(&g, &file_header, sizeof(GUID))) { if (!memcmp(&g, &file_header, sizeof(GUID))) {
get_guid(pb, &asf->hdr.guid); get_guid(pb, &asf->hdr.guid);
asf->hdr.file_size = get_le64(pb); asf->hdr.file_size = get_le64(pb);
...@@ -207,11 +207,11 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -207,11 +207,11 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
st = av_new_stream(s, 0); st = av_new_stream(s, 0);
if (!st) if (!st)
goto fail; return AVERROR(ENOMEM);
av_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */ av_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
asf_st = av_mallocz(sizeof(ASFStream)); asf_st = av_mallocz(sizeof(ASFStream));
if (!asf_st) if (!asf_st)
goto fail; return AVERROR(ENOMEM);
st->priv_data = asf_st; st->priv_data = asf_st;
start_time = asf->hdr.preroll; start_time = asf->hdr.preroll;
...@@ -232,7 +232,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -232,7 +232,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
test_for_ext_stream_audio = 1; test_for_ext_stream_audio = 1;
type = CODEC_TYPE_UNKNOWN; type = CODEC_TYPE_UNKNOWN;
} else { } else {
goto fail; return -1;
} }
get_guid(pb, &g); get_guid(pb, &g);
total_size = get_le64(pb); total_size = get_le64(pb);
...@@ -513,7 +513,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -513,7 +513,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
} }
#endif #endif
} else if (url_feof(pb)) { } else if (url_feof(pb)) {
goto fail; return -1;
} else { } else {
url_fseek(pb, gsize - 24, SEEK_CUR); url_fseek(pb, gsize - 24, SEEK_CUR);
} }
...@@ -523,7 +523,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -523,7 +523,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
get_byte(pb); get_byte(pb);
get_byte(pb); get_byte(pb);
if (url_feof(pb)) if (url_feof(pb))
goto fail; return -1;
asf->data_offset = url_ftell(pb); asf->data_offset = url_ftell(pb);
asf->packet_size_left = 0; asf->packet_size_left = 0;
...@@ -543,17 +543,6 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -543,17 +543,6 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
} }
return 0; return 0;
fail:
for(i=0;i<s->nb_streams;i++) {
AVStream *st = s->streams[i];
if (st) {
av_free(st->priv_data);
av_free(st->codec->extradata);
}
av_free(st);
}
return -1;
} }
#define DO_2BITS(bits, var, defval) \ #define DO_2BITS(bits, var, defval) \
......
...@@ -597,10 +597,6 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -597,10 +597,6 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
/* check stream number */ /* check stream number */
if (stream_index != s->nb_streams - 1) { if (stream_index != s->nb_streams - 1) {
fail: fail:
for(i=0;i<s->nb_streams;i++) {
av_freep(&s->streams[i]->codec->extradata);
av_freep(&s->streams[i]);
}
return -1; return -1;
} }
......
...@@ -297,7 +297,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -297,7 +297,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
for(;;) { for(;;) {
if (url_feof(pb)) if (url_feof(pb))
goto fail; return -1;
tag = get_le32(pb); tag = get_le32(pb);
tag_size = get_be32(pb); tag_size = get_be32(pb);
get_be16(pb); get_be16(pb);
...@@ -311,7 +311,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -311,7 +311,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
tag_size); tag_size);
#endif #endif
if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A')) if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
goto fail; return -1;
switch(tag) { switch(tag) {
case MKTAG('P', 'R', 'O', 'P'): case MKTAG('P', 'R', 'O', 'P'):
/* file header */ /* file header */
...@@ -336,7 +336,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -336,7 +336,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
case MKTAG('M', 'D', 'P', 'R'): case MKTAG('M', 'D', 'P', 'R'):
st = av_new_stream(s, 0); st = av_new_stream(s, 0);
if (!st) if (!st)
goto fail; return AVERROR(ENOMEM);
st->id = get_be16(pb); st->id = get_be16(pb);
get_be32(pb); /* max bit rate */ get_be32(pb); /* max bit rate */
st->codec->bit_rate = get_be32(pb); /* bit rate */ st->codec->bit_rate = get_be32(pb); /* bit rate */
...@@ -369,12 +369,6 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -369,12 +369,6 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
get_be32(pb); /* next data header */ get_be32(pb); /* next data header */
rm->curpic_num = -1; rm->curpic_num = -1;
return 0; return 0;
fail:
for(i=0;i<s->nb_streams;i++) {
av_free(s->streams[i]);
}
return AVERROR(EIO);
} }
static int get_num(ByteIOContext *pb, int *len) static int get_num(ByteIOContext *pb, int *len)
......
...@@ -405,7 +405,16 @@ int av_open_input_stream(AVFormatContext **ic_ptr, ...@@ -405,7 +405,16 @@ int av_open_input_stream(AVFormatContext **ic_ptr,
return 0; return 0;
fail: fail:
if (ic) { if (ic) {
int i;
av_freep(&ic->priv_data); av_freep(&ic->priv_data);
for(i=0;i<ic->nb_streams;i++) {
AVStream *st = ic->streams[i];
if (st) {
av_free(st->priv_data);
av_free(st->codec->extradata);
}
av_free(st);
}
} }
av_free(ic); av_free(ic);
*ic_ptr = NULL; *ic_ptr = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment