From patchwork Fri Dec 27 21:14:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17006 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 88C3244B0EA for ; Fri, 27 Dec 2019 23:14:39 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7694568AD91; Fri, 27 Dec 2019 23:14:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EC144689247 for ; Fri, 27 Dec 2019 23:14:30 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id BB345E3E4E; Fri, 27 Dec 2019 22:14:30 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BCNhq6NCyI_D; Fri, 27 Dec 2019 22:14:28 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 25234E391B; Fri, 27 Dec 2019 22:14:27 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Dec 2019 22:14:08 +0100 Message-Id: <20191227211411.30293-5-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20191227211411.30293-1-cus@passwd.hu> References: <20191227211411.30293-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 5/8] avformat/img2enc: cleanup IO contexts on error X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- libavformat/img2enc.c | 13 ++++++++++--- 1 file 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)