[FFmpeg-devel] [PATCH] avformat/mov: free the infe allocated streams on private data allocation failure
James Almer
jamrial at gmail.com
Sat Apr 27 03:26:38 EEST 2024
Signed-off-by: James Almer <jamrial at gmail.com>
---
libavformat/mov.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index e52a83c82e..7f81419bd8 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -84,6 +84,7 @@ typedef struct MOVParseTableEntry {
static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom);
static int mov_read_mfra(MOVContext *c, AVIOContext *f);
+static void mov_free_stream_context(AVFormatContext *s, AVStream *st);
static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, unsigned int* allocated_size,
int count, int duration);
@@ -5156,8 +5157,10 @@ static int heif_add_stream(MOVContext *c, HEIFItem *item)
if (!st)
return AVERROR(ENOMEM);
sc = av_mallocz(sizeof(MOVStreamContext));
- if (!sc)
+ if (!sc) {
+ ff_remove_stream(c->fc, st);
return AVERROR(ENOMEM);
+ }
item->st = st;
st->id = item->item_id;
@@ -5181,27 +5184,31 @@ static int heif_add_stream(MOVContext *c, HEIFItem *item)
sc->stsc_count = 1;
sc->stsc_data = av_malloc_array(1, sizeof(*sc->stsc_data));
if (!sc->stsc_data)
- return AVERROR(ENOMEM);
+ goto fail;
sc->stsc_data[0].first = 1;
sc->stsc_data[0].count = 1;
sc->stsc_data[0].id = 1;
sc->chunk_count = 1;
sc->chunk_offsets = av_malloc_array(1, sizeof(*sc->chunk_offsets));
if (!sc->chunk_offsets)
- return AVERROR(ENOMEM);
+ goto fail;
sc->sample_count = 1;
sc->sample_sizes = av_malloc_array(1, sizeof(*sc->sample_sizes));
if (!sc->sample_sizes)
- return AVERROR(ENOMEM);
+ goto fail;
sc->stts_count = 1;
sc->stts_data = av_malloc_array(1, sizeof(*sc->stts_data));
if (!sc->stts_data)
- return AVERROR(ENOMEM);
+ goto fail;
sc->stts_data[0].count = 1;
// Not used for still images. But needed by mov_build_index.
sc->stts_data[0].duration = 0;
return 0;
+fail:
+ mov_free_stream_context(c->fc, st);
+ ff_remove_stream(c->fc, st);
+ return AVERROR(ENOMEM);
}
static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom)
--
2.44.0
More information about the ffmpeg-devel
mailing list