summaryrefslogtreecommitdiff
path: root/libavformat/img2enc.c
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2019-12-26 21:08:22 +0100
committerMarton Balint <cus@passwd.hu>2020-01-03 11:23:55 +0100
commit57df8839e1b2219a1646592fa4f96887268c2dfd (patch)
treee8c30e031e450125e887630bfa9be0d14429c5ff /libavformat/img2enc.c
parent43d5ddb4b551845ca2191eb68347355323658c38 (diff)
downloadffmpeg-57df8839e1b2219a1646592fa4f96887268c2dfd.tar.gz
avformat/img2enc: cleanup IO contexts on error
Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavformat/img2enc.c')
-rw-r--r--libavformat/img2enc.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index a976d07acc..14e6d641f9 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -124,7 +124,7 @@ static int write_packet_pipe(AVFormatContext *s, AVPacket *pkt)
static int write_packet(AVFormatContext *s, AVPacket *pkt)
{
VideoMuxData *img = s->priv_data;
- AVIOContext *pb[4];
+ AVIOContext *pb[4] = {0};
char filename[1024];
AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(par->format);
@@ -162,7 +162,8 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
av_strlcpy(img->target[i], filename, sizeof(img->target[i]));
if (s->io_open(s, &pb[i], img->use_rename ? img->tmp[i] : filename, AVIO_FLAG_WRITE, NULL) < 0) {
av_log(s, AV_LOG_ERROR, "Could not open file : %s\n", img->use_rename ? img->tmp[i] : filename);
- return AVERROR(EIO);
+ ret = AVERROR(EIO);
+ goto fail;
}
if (!img->split_planes || i+1 >= desc->nb_components)
@@ -191,7 +192,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
} else if (img->muxer) {
ret = write_muxed_file(s, pb[0], pkt);
if (ret < 0)
- return ret;
+ goto fail;
} else {
avio_write(pb[0], pkt->data, pkt->size);
}
@@ -205,6 +206,12 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
img->img_number++;
return 0;
+
+fail:
+ for (i = 0; i < FF_ARRAY_ELEMS(pb); i++)
+ if (pb[i])
+ ff_format_io_close(s, &pb[i]);
+ return ret;
}
static int query_codec(enum AVCodecID id, int std_compliance)