summaryrefslogtreecommitdiff
path: root/libavformat/movenc.c
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2014-11-02 23:50:47 +0200
committerMartin Storsjö <martin@martin.st>2014-11-08 11:14:08 +0200
commit8cb7b7b461b52898765b38e3eff68c0ce88347f3 (patch)
tree461e89092a9ba380771955d2a40854c4db0422d6 /libavformat/movenc.c
parent95a449d3ce8e15522df47a80a8a4593ea5c2b1bb (diff)
movenc: Avoid leaking locally allocated data when returning on errors
Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/movenc.c')
-rw-r--r--libavformat/movenc.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index e2a6bbc2fd..bb1dc8a301 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -3065,7 +3065,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
MOVTrack *trk = &mov->tracks[pkt->stream_index];
AVCodecContext *enc = trk->enc;
unsigned int samples_in_chunk = 0;
- int size = pkt->size;
+ int size = pkt->size, ret = 0;
uint8_t *reformatted_data = NULL;
if (mov->flags & FF_MOV_FLAG_FRAGMENT) {
@@ -3139,16 +3139,20 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
/* copy frame to create needed atoms */
trk->vos_len = size;
trk->vos_data = av_malloc(size);
- if (!trk->vos_data)
- return AVERROR(ENOMEM);
+ if (!trk->vos_data) {
+ ret = AVERROR(ENOMEM);
+ goto err;
+ }
memcpy(trk->vos_data, pkt->data, size);
}
if (trk->entry >= trk->cluster_capacity) {
unsigned new_capacity = 2 * (trk->entry + MOV_INDEX_CLUSTER_SIZE);
if (av_reallocp_array(&trk->cluster, new_capacity,
- sizeof(*trk->cluster)))
- return AVERROR(ENOMEM);
+ sizeof(*trk->cluster))) {
+ ret = AVERROR(ENOMEM);
+ goto err;
+ }
trk->cluster_capacity = new_capacity;
}
@@ -3212,8 +3216,10 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams)
ff_mov_add_hinted_packet(s, pkt, trk->hint_track, trk->entry,
reformatted_data, size);
+
+err:
av_free(reformatted_data);
- return 0;
+ return ret;
}
static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)