[FFmpeg-cvslog] avformat/mov: Fix memleaks upon read_header failure

2020-07-03 Thread Andreas Rheinhardt
ffmpeg | branch: release/3.3 | Andreas Rheinhardt 
 | Sun Jun 14 00:37:40 2020 +0200| 
[19b1f676f66ec26afb2c9c9501d5451847a7c9b5] | committer: Andreas Rheinhardt

avformat/mov: Fix memleaks upon read_header failure

By default, a demuxer's read_close function is not called automatically
if an error happens when reading the header; instead it is up to the
demuxer to clean up after itself in this case. The mov demuxer did this
by calling its read_close function when it encountered some errors when
reading the header. Yet for other errors (mostly adding side-data to
streams) this has been forgotten, so that all the internal structures
of the demuxer leak.

This commit fixes this by making sure mov_read_close is called when
necessary.

Signed-off-by: Andreas Rheinhardt 
(cherry picked from commit ac378c535be907ee383dafb430be7216a2920982)
Signed-off-by: Andreas Rheinhardt 

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

 libavformat/mov.c | 29 +++--
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 105084813e..0c354ab387 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -6024,14 +6024,13 @@ static int mov_read_header(AVFormatContext *s)
 avio_seek(pb, 0, SEEK_SET);
 if ((err = mov_read_default(mov, pb, atom)) < 0) {
 av_log(s, AV_LOG_ERROR, "error reading header\n");
-mov_read_close(s);
-return err;
+goto fail;
 }
 } while ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mov->found_moov && 
!mov->moov_retry++);
 if (!mov->found_moov) {
 av_log(s, AV_LOG_ERROR, "moov atom not found\n");
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", 
avio_tell(pb));
 
@@ -6084,7 +6083,7 @@ static int mov_read_header(AVFormatContext *s)
 }
 if (st->codecpar->codec_id == AV_CODEC_ID_DVD_SUBTITLE) {
 if ((err = mov_rewrite_dvd_sub_extradata(st)) < 0)
-return err;
+goto fail;
 }
 }
 if (mov->handbrake_version &&
@@ -6104,8 +6103,8 @@ static int mov_read_header(AVFormatContext *s)
 if (sc->data_size > INT64_MAX / sc->time_scale / 8) {
 av_log(s, AV_LOG_ERROR, "Overflow during bit rate 
calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / 
st->duration;
 }
@@ -6120,8 +6119,8 @@ static int mov_read_header(AVFormatContext *s)
 if (sc->data_size > INT64_MAX / sc->time_scale / 8) {
 av_log(s, AV_LOG_ERROR, "Overflow during bit rate 
calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale /
 sc->duration_for_fps;
@@ -6145,8 +6144,7 @@ static int mov_read_header(AVFormatContext *s)
 case AVMEDIA_TYPE_AUDIO:
 err = ff_replaygain_export(st, s->metadata);
 if (err < 0) {
-mov_read_close(s);
-return err;
+goto fail;
 }
 break;
 case AVMEDIA_TYPE_VIDEO:
@@ -6154,7 +6152,7 @@ static int mov_read_header(AVFormatContext *s)
 err = av_stream_add_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, 
(uint8_t*)sc->display_matrix,
   sizeof(int32_t) * 9);
 if (err < 0)
-return err;
+goto fail;
 
 sc->display_matrix = NULL;
 }
@@ -6163,7 +6161,7 @@ static int mov_read_header(AVFormatContext *s)
   (uint8_t *)sc->stereo3d,
   sizeof(*sc->stereo3d));
 if (err < 0)
-return err;
+goto fail;
 
 sc->stereo3d = NULL;
 }
@@ -6172,7 +6170,7 @@ static int mov_read_header(AVFormatContext *s)
   (uint8_t *)sc->spherical,
   sc->spherical_size);
 if (err < 0)
-return err;
+goto fail;
 
 sc->spherical = NULL;
 }
@@ -6182,6 

[FFmpeg-cvslog] avformat/mov: Fix memleaks upon read_header failure

2020-07-02 Thread Andreas Rheinhardt
ffmpeg | branch: release/3.4 | Andreas Rheinhardt 
 | Sun Jun 14 00:37:40 2020 +0200| 
[9e404b60b17e1430aa587e2083bcd109f4fcff32] | committer: Andreas Rheinhardt

avformat/mov: Fix memleaks upon read_header failure

By default, a demuxer's read_close function is not called automatically
if an error happens when reading the header; instead it is up to the
demuxer to clean up after itself in this case. The mov demuxer did this
by calling its read_close function when it encountered some errors when
reading the header. Yet for other errors (mostly adding side-data to
streams) this has been forgotten, so that all the internal structures
of the demuxer leak.

This commit fixes this by making sure mov_read_close is called when
necessary.

Signed-off-by: Andreas Rheinhardt 
(cherry picked from commit ac378c535be907ee383dafb430be7216a2920982)
Signed-off-by: Andreas Rheinhardt 

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

 libavformat/mov.c | 33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 4da44b1bb9..08c83c22f7 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -6305,14 +6305,13 @@ static int mov_read_header(AVFormatContext *s)
 avio_seek(pb, 0, SEEK_SET);
 if ((err = mov_read_default(mov, pb, atom)) < 0) {
 av_log(s, AV_LOG_ERROR, "error reading header\n");
-mov_read_close(s);
-return err;
+goto fail;
 }
 } while ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mov->found_moov && 
!mov->moov_retry++);
 if (!mov->found_moov) {
 av_log(s, AV_LOG_ERROR, "moov atom not found\n");
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", 
avio_tell(pb));
 
@@ -6365,7 +6364,7 @@ static int mov_read_header(AVFormatContext *s)
 }
 if (st->codecpar->codec_id == AV_CODEC_ID_DVD_SUBTITLE) {
 if ((err = mov_rewrite_dvd_sub_extradata(st)) < 0)
-return err;
+goto fail;
 }
 }
 if (mov->handbrake_version &&
@@ -6385,8 +6384,8 @@ static int mov_read_header(AVFormatContext *s)
 if (sc->data_size > INT64_MAX / sc->time_scale / 8) {
 av_log(s, AV_LOG_ERROR, "Overflow during bit rate 
calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / 
st->duration;
 }
@@ -6401,8 +6400,8 @@ static int mov_read_header(AVFormatContext *s)
 if (sc->data_size > INT64_MAX / sc->time_scale / 8) {
 av_log(s, AV_LOG_ERROR, "Overflow during bit rate 
calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale /
 sc->duration_for_fps;
@@ -6426,8 +6425,7 @@ static int mov_read_header(AVFormatContext *s)
 case AVMEDIA_TYPE_AUDIO:
 err = ff_replaygain_export(st, s->metadata);
 if (err < 0) {
-mov_read_close(s);
-return err;
+goto fail;
 }
 break;
 case AVMEDIA_TYPE_VIDEO:
@@ -6435,7 +6433,7 @@ static int mov_read_header(AVFormatContext *s)
 err = av_stream_add_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, 
(uint8_t*)sc->display_matrix,
   sizeof(int32_t) * 9);
 if (err < 0)
-return err;
+goto fail;
 
 sc->display_matrix = NULL;
 }
@@ -6444,7 +6442,7 @@ static int mov_read_header(AVFormatContext *s)
   (uint8_t *)sc->stereo3d,
   sizeof(*sc->stereo3d));
 if (err < 0)
-return err;
+goto fail;
 
 sc->stereo3d = NULL;
 }
@@ -6453,7 +6451,7 @@ static int mov_read_header(AVFormatContext *s)
   (uint8_t *)sc->spherical,
   sc->spherical_size);
 if (err < 0)
-return err;
+goto fail;
 
 sc->spherical = NULL;
 }
@@ -6462,7 

[FFmpeg-cvslog] avformat/mov: Fix memleaks upon read_header failure

2020-07-02 Thread Andreas Rheinhardt
ffmpeg | branch: release/4.0 | Andreas Rheinhardt 
 | Sun Jun 14 00:37:40 2020 +0200| 
[85200b8c026b938b09dee016b5729afde880d850] | committer: Andreas Rheinhardt

avformat/mov: Fix memleaks upon read_header failure

By default, a demuxer's read_close function is not called automatically
if an error happens when reading the header; instead it is up to the
demuxer to clean up after itself in this case. The mov demuxer did this
by calling its read_close function when it encountered some errors when
reading the header. Yet for other errors (mostly adding side-data to
streams) this has been forgotten, so that all the internal structures
of the demuxer leak.

This commit fixes this by making sure mov_read_close is called when
necessary.

Signed-off-by: Andreas Rheinhardt 
(cherry picked from commit ac378c535be907ee383dafb430be7216a2920982)
Signed-off-by: Andreas Rheinhardt 

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

 libavformat/mov.c | 33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index bad553d2fa..f8adbf6cd5 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -6824,14 +6824,13 @@ static int mov_read_header(AVFormatContext *s)
 avio_seek(pb, 0, SEEK_SET);
 if ((err = mov_read_default(mov, pb, atom)) < 0) {
 av_log(s, AV_LOG_ERROR, "error reading header\n");
-mov_read_close(s);
-return err;
+goto fail;
 }
 } while ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mov->found_moov && 
!mov->moov_retry++);
 if (!mov->found_moov) {
 av_log(s, AV_LOG_ERROR, "moov atom not found\n");
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", 
avio_tell(pb));
 
@@ -6884,7 +6883,7 @@ static int mov_read_header(AVFormatContext *s)
 }
 if (st->codecpar->codec_id == AV_CODEC_ID_DVD_SUBTITLE) {
 if ((err = mov_rewrite_dvd_sub_extradata(st)) < 0)
-return err;
+goto fail;
 }
 }
 if (mov->handbrake_version &&
@@ -6904,8 +6903,8 @@ static int mov_read_header(AVFormatContext *s)
 if (sc->data_size > INT64_MAX / sc->time_scale / 8) {
 av_log(s, AV_LOG_ERROR, "Overflow during bit rate 
calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / 
st->duration;
 }
@@ -6920,8 +6919,8 @@ static int mov_read_header(AVFormatContext *s)
 if (sc->data_size > INT64_MAX / sc->time_scale / 8) {
 av_log(s, AV_LOG_ERROR, "Overflow during bit rate 
calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale /
 sc->duration_for_fps;
@@ -6945,8 +6944,7 @@ static int mov_read_header(AVFormatContext *s)
 case AVMEDIA_TYPE_AUDIO:
 err = ff_replaygain_export(st, s->metadata);
 if (err < 0) {
-mov_read_close(s);
-return err;
+goto fail;
 }
 break;
 case AVMEDIA_TYPE_VIDEO:
@@ -6954,7 +6952,7 @@ static int mov_read_header(AVFormatContext *s)
 err = av_stream_add_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, 
(uint8_t*)sc->display_matrix,
   sizeof(int32_t) * 9);
 if (err < 0)
-return err;
+goto fail;
 
 sc->display_matrix = NULL;
 }
@@ -6963,7 +6961,7 @@ static int mov_read_header(AVFormatContext *s)
   (uint8_t *)sc->stereo3d,
   sizeof(*sc->stereo3d));
 if (err < 0)
-return err;
+goto fail;
 
 sc->stereo3d = NULL;
 }
@@ -6972,7 +6970,7 @@ static int mov_read_header(AVFormatContext *s)
   (uint8_t *)sc->spherical,
   sc->spherical_size);
 if (err < 0)
-return err;
+goto fail;
 
 sc->spherical = 

[FFmpeg-cvslog] avformat/mov: Fix memleaks upon read_header failure

2020-07-01 Thread Andreas Rheinhardt
ffmpeg | branch: release/4.1 | Andreas Rheinhardt 
 | Sun Jun 14 00:37:40 2020 +0200| 
[430cf25553666adb28b6a54f9a535ef1d7debe9d] | committer: Andreas Rheinhardt

avformat/mov: Fix memleaks upon read_header failure

By default, a demuxer's read_close function is not called automatically
if an error happens when reading the header; instead it is up to the
demuxer to clean up after itself in this case. The mov demuxer did this
by calling its read_close function when it encountered some errors when
reading the header. Yet for other errors (mostly adding side-data to
streams) this has been forgotten, so that all the internal structures
of the demuxer leak.

This commit fixes this by making sure mov_read_close is called when
necessary.

Signed-off-by: Andreas Rheinhardt 
(cherry picked from commit ac378c535be907ee383dafb430be7216a2920982)
Signed-off-by: Andreas Rheinhardt 

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

 libavformat/mov.c | 33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 6d41823553..8825f2982b 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7422,14 +7422,13 @@ static int mov_read_header(AVFormatContext *s)
 avio_seek(pb, 0, SEEK_SET);
 if ((err = mov_read_default(mov, pb, atom)) < 0) {
 av_log(s, AV_LOG_ERROR, "error reading header\n");
-mov_read_close(s);
-return err;
+goto fail;
 }
 } while ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mov->found_moov && 
!mov->moov_retry++);
 if (!mov->found_moov) {
 av_log(s, AV_LOG_ERROR, "moov atom not found\n");
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", 
avio_tell(pb));
 
@@ -7482,7 +7481,7 @@ static int mov_read_header(AVFormatContext *s)
 }
 if (st->codecpar->codec_id == AV_CODEC_ID_DVD_SUBTITLE) {
 if ((err = mov_rewrite_dvd_sub_extradata(st)) < 0)
-return err;
+goto fail;
 }
 }
 if (mov->handbrake_version &&
@@ -7502,8 +7501,8 @@ static int mov_read_header(AVFormatContext *s)
 if (sc->data_size > INT64_MAX / sc->time_scale / 8) {
 av_log(s, AV_LOG_ERROR, "Overflow during bit rate 
calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / 
st->duration;
 }
@@ -7518,8 +7517,8 @@ static int mov_read_header(AVFormatContext *s)
 if (sc->data_size > INT64_MAX / sc->time_scale / 8) {
 av_log(s, AV_LOG_ERROR, "Overflow during bit rate 
calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale /
 sc->duration_for_fps;
@@ -7543,8 +7542,7 @@ static int mov_read_header(AVFormatContext *s)
 case AVMEDIA_TYPE_AUDIO:
 err = ff_replaygain_export(st, s->metadata);
 if (err < 0) {
-mov_read_close(s);
-return err;
+goto fail;
 }
 break;
 case AVMEDIA_TYPE_VIDEO:
@@ -7552,7 +7550,7 @@ static int mov_read_header(AVFormatContext *s)
 err = av_stream_add_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, 
(uint8_t*)sc->display_matrix,
   sizeof(int32_t) * 9);
 if (err < 0)
-return err;
+goto fail;
 
 sc->display_matrix = NULL;
 }
@@ -7561,7 +7559,7 @@ static int mov_read_header(AVFormatContext *s)
   (uint8_t *)sc->stereo3d,
   sizeof(*sc->stereo3d));
 if (err < 0)
-return err;
+goto fail;
 
 sc->stereo3d = NULL;
 }
@@ -7570,7 +7568,7 @@ static int mov_read_header(AVFormatContext *s)
   (uint8_t *)sc->spherical,
   sc->spherical_size);
 if (err < 0)
-return err;
+goto fail;
 
 sc->spherical = 

[FFmpeg-cvslog] avformat/mov: Fix memleaks upon read_header failure

2020-07-01 Thread Andreas Rheinhardt
ffmpeg | branch: release/4.2 | Andreas Rheinhardt 
 | Sun Jun 14 00:37:40 2020 +0200| 
[bb03a54e408cb95446b6f85e3f3273a1a366a3d3] | committer: Andreas Rheinhardt

avformat/mov: Fix memleaks upon read_header failure

By default, a demuxer's read_close function is not called automatically
if an error happens when reading the header; instead it is up to the
demuxer to clean up after itself in this case. The mov demuxer did this
by calling its read_close function when it encountered some errors when
reading the header. Yet for other errors (mostly adding side-data to
streams) this has been forgotten, so that all the internal structures
of the demuxer leak.

This commit fixes this by making sure mov_read_close is called when
necessary.

Signed-off-by: Andreas Rheinhardt 
(cherry picked from commit ac378c535be907ee383dafb430be7216a2920982)
Signed-off-by: Andreas Rheinhardt 

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

 libavformat/mov.c | 33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 6b0e101af9..da26b489a5 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7425,14 +7425,13 @@ static int mov_read_header(AVFormatContext *s)
 avio_seek(pb, 0, SEEK_SET);
 if ((err = mov_read_default(mov, pb, atom)) < 0) {
 av_log(s, AV_LOG_ERROR, "error reading header\n");
-mov_read_close(s);
-return err;
+goto fail;
 }
 } while ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mov->found_moov && 
!mov->moov_retry++);
 if (!mov->found_moov) {
 av_log(s, AV_LOG_ERROR, "moov atom not found\n");
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", 
avio_tell(pb));
 
@@ -7485,7 +7484,7 @@ static int mov_read_header(AVFormatContext *s)
 }
 if (st->codecpar->codec_id == AV_CODEC_ID_DVD_SUBTITLE) {
 if ((err = mov_rewrite_dvd_sub_extradata(st)) < 0)
-return err;
+goto fail;
 }
 }
 if (mov->handbrake_version &&
@@ -7505,8 +7504,8 @@ static int mov_read_header(AVFormatContext *s)
 if (sc->data_size > INT64_MAX / sc->time_scale / 8) {
 av_log(s, AV_LOG_ERROR, "Overflow during bit rate 
calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / 
st->duration;
 }
@@ -7521,8 +7520,8 @@ static int mov_read_header(AVFormatContext *s)
 if (sc->data_size > INT64_MAX / sc->time_scale / 8) {
 av_log(s, AV_LOG_ERROR, "Overflow during bit rate 
calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale /
 sc->duration_for_fps;
@@ -7546,8 +7545,7 @@ static int mov_read_header(AVFormatContext *s)
 case AVMEDIA_TYPE_AUDIO:
 err = ff_replaygain_export(st, s->metadata);
 if (err < 0) {
-mov_read_close(s);
-return err;
+goto fail;
 }
 break;
 case AVMEDIA_TYPE_VIDEO:
@@ -7555,7 +7553,7 @@ static int mov_read_header(AVFormatContext *s)
 err = av_stream_add_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, 
(uint8_t*)sc->display_matrix,
   sizeof(int32_t) * 9);
 if (err < 0)
-return err;
+goto fail;
 
 sc->display_matrix = NULL;
 }
@@ -7564,7 +7562,7 @@ static int mov_read_header(AVFormatContext *s)
   (uint8_t *)sc->stereo3d,
   sizeof(*sc->stereo3d));
 if (err < 0)
-return err;
+goto fail;
 
 sc->stereo3d = NULL;
 }
@@ -7573,7 +7571,7 @@ static int mov_read_header(AVFormatContext *s)
   (uint8_t *)sc->spherical,
   sc->spherical_size);
 if (err < 0)
-return err;
+goto fail;
 
 sc->spherical = 

[FFmpeg-cvslog] avformat/mov: Fix memleaks upon read_header failure

2020-06-15 Thread Andreas Rheinhardt
ffmpeg | branch: release/4.3 | Andreas Rheinhardt 
 | Sun Jun 14 00:37:40 2020 +0200| 
[30d66abc801ec54f81f49b0aa01a36692a744266] | committer: Andreas Rheinhardt

avformat/mov: Fix memleaks upon read_header failure

By default, a demuxer's read_close function is not called automatically
if an error happens when reading the header; instead it is up to the
demuxer to clean up after itself in this case. The mov demuxer did this
by calling its read_close function when it encountered some errors when
reading the header. Yet for other errors (mostly adding side-data to
streams) this has been forgotten, so that all the internal structures
of the demuxer leak.

This commit fixes this by making sure mov_read_close is called when
necessary.

Signed-off-by: Andreas Rheinhardt 
(cherry picked from commit ac378c535be907ee383dafb430be7216a2920982)

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

 libavformat/mov.c | 33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 2fc27d2aec..47bbb3697d 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7580,14 +7580,13 @@ static int mov_read_header(AVFormatContext *s)
 avio_seek(pb, 0, SEEK_SET);
 if ((err = mov_read_default(mov, pb, atom)) < 0) {
 av_log(s, AV_LOG_ERROR, "error reading header\n");
-mov_read_close(s);
-return err;
+goto fail;
 }
 } while ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mov->found_moov && 
!mov->moov_retry++);
 if (!mov->found_moov) {
 av_log(s, AV_LOG_ERROR, "moov atom not found\n");
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", 
avio_tell(pb));
 
@@ -7640,7 +7639,7 @@ static int mov_read_header(AVFormatContext *s)
 }
 if (st->codecpar->codec_id == AV_CODEC_ID_DVD_SUBTITLE) {
 if ((err = mov_rewrite_dvd_sub_extradata(st)) < 0)
-return err;
+goto fail;
 }
 }
 if (mov->handbrake_version &&
@@ -7660,8 +7659,8 @@ static int mov_read_header(AVFormatContext *s)
 if (sc->data_size > INT64_MAX / sc->time_scale / 8) {
 av_log(s, AV_LOG_ERROR, "Overflow during bit rate 
calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / 
st->duration;
 }
@@ -7676,8 +7675,8 @@ static int mov_read_header(AVFormatContext *s)
 if (sc->data_size > INT64_MAX / sc->time_scale / 8) {
 av_log(s, AV_LOG_ERROR, "Overflow during bit rate 
calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale /
 sc->duration_for_fps;
@@ -7701,8 +7700,7 @@ static int mov_read_header(AVFormatContext *s)
 case AVMEDIA_TYPE_AUDIO:
 err = ff_replaygain_export(st, s->metadata);
 if (err < 0) {
-mov_read_close(s);
-return err;
+goto fail;
 }
 break;
 case AVMEDIA_TYPE_VIDEO:
@@ -7710,7 +7708,7 @@ static int mov_read_header(AVFormatContext *s)
 err = av_stream_add_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, 
(uint8_t*)sc->display_matrix,
   sizeof(int32_t) * 9);
 if (err < 0)
-return err;
+goto fail;
 
 sc->display_matrix = NULL;
 }
@@ -7719,7 +7717,7 @@ static int mov_read_header(AVFormatContext *s)
   (uint8_t *)sc->stereo3d,
   sizeof(*sc->stereo3d));
 if (err < 0)
-return err;
+goto fail;
 
 sc->stereo3d = NULL;
 }
@@ -7728,7 +7726,7 @@ static int mov_read_header(AVFormatContext *s)
   (uint8_t *)sc->spherical,
   sc->spherical_size);
 if (err < 0)
-return err;
+goto fail;
 
 sc->spherical = NULL;
 }
@@ -7737,7 +7735,7 

[FFmpeg-cvslog] avformat/mov: Fix memleaks upon read_header failure

2020-06-15 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Jun 14 00:37:40 2020 +0200| [ac378c535be907ee383dafb430be7216a2920982] | 
committer: Andreas Rheinhardt

avformat/mov: Fix memleaks upon read_header failure

By default, a demuxer's read_close function is not called automatically
if an error happens when reading the header; instead it is up to the
demuxer to clean up after itself in this case. The mov demuxer did this
by calling its read_close function when it encountered some errors when
reading the header. Yet for other errors (mostly adding side-data to
streams) this has been forgotten, so that all the internal structures
of the demuxer leak.

This commit fixes this by making sure mov_read_close is called when
necessary.

Signed-off-by: Andreas Rheinhardt 

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

 libavformat/mov.c | 33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 2fc27d2aec..47bbb3697d 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7580,14 +7580,13 @@ static int mov_read_header(AVFormatContext *s)
 avio_seek(pb, 0, SEEK_SET);
 if ((err = mov_read_default(mov, pb, atom)) < 0) {
 av_log(s, AV_LOG_ERROR, "error reading header\n");
-mov_read_close(s);
-return err;
+goto fail;
 }
 } while ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mov->found_moov && 
!mov->moov_retry++);
 if (!mov->found_moov) {
 av_log(s, AV_LOG_ERROR, "moov atom not found\n");
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", 
avio_tell(pb));
 
@@ -7640,7 +7639,7 @@ static int mov_read_header(AVFormatContext *s)
 }
 if (st->codecpar->codec_id == AV_CODEC_ID_DVD_SUBTITLE) {
 if ((err = mov_rewrite_dvd_sub_extradata(st)) < 0)
-return err;
+goto fail;
 }
 }
 if (mov->handbrake_version &&
@@ -7660,8 +7659,8 @@ static int mov_read_header(AVFormatContext *s)
 if (sc->data_size > INT64_MAX / sc->time_scale / 8) {
 av_log(s, AV_LOG_ERROR, "Overflow during bit rate 
calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / 
st->duration;
 }
@@ -7676,8 +7675,8 @@ static int mov_read_header(AVFormatContext *s)
 if (sc->data_size > INT64_MAX / sc->time_scale / 8) {
 av_log(s, AV_LOG_ERROR, "Overflow during bit rate 
calculation %"PRId64" * 8 * %d\n",
sc->data_size, sc->time_scale);
-mov_read_close(s);
-return AVERROR_INVALIDDATA;
+err = AVERROR_INVALIDDATA;
+goto fail;
 }
 st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale /
 sc->duration_for_fps;
@@ -7701,8 +7700,7 @@ static int mov_read_header(AVFormatContext *s)
 case AVMEDIA_TYPE_AUDIO:
 err = ff_replaygain_export(st, s->metadata);
 if (err < 0) {
-mov_read_close(s);
-return err;
+goto fail;
 }
 break;
 case AVMEDIA_TYPE_VIDEO:
@@ -7710,7 +7708,7 @@ static int mov_read_header(AVFormatContext *s)
 err = av_stream_add_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, 
(uint8_t*)sc->display_matrix,
   sizeof(int32_t) * 9);
 if (err < 0)
-return err;
+goto fail;
 
 sc->display_matrix = NULL;
 }
@@ -7719,7 +7717,7 @@ static int mov_read_header(AVFormatContext *s)
   (uint8_t *)sc->stereo3d,
   sizeof(*sc->stereo3d));
 if (err < 0)
-return err;
+goto fail;
 
 sc->stereo3d = NULL;
 }
@@ -7728,7 +7726,7 @@ static int mov_read_header(AVFormatContext *s)
   (uint8_t *)sc->spherical,
   sc->spherical_size);
 if (err < 0)
-return err;
+goto fail;
 
 sc->spherical = NULL;
 }
@@ -7737,7 +7735,7 @@ static int mov_read_header(AVFormatContext *s)