From patchwork Tue Jan 7 13:55:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 17235 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 DAD4C44AC83 for ; Tue, 7 Jan 2020 15:56:18 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BDFA268AD22; Tue, 7 Jan 2020 15:56:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2DCF568AB4A for ; Tue, 7 Jan 2020 15:56:11 +0200 (EET) Received: by mail-wm1-f50.google.com with SMTP id p9so19050314wmc.2 for ; Tue, 07 Jan 2020 05:56:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ODfyDhzVBXotG8zgG2GcMb0+UhfaPDC8syC0S1M9rlE=; b=JkBf1CqWrKDS+M4rdAyXssesqco/9VqHhGtMsyBfCqp7ff7IuxPi6QA1ZdINfpKAHK Dg7cCMI5SyngMTjrvYh5dQ3Q9eai/IptT7SvAR7HOyiwahA9c3X1wvdOO4HkDlxxj1vD ul+seZcEs4inbKD4eFhgSPyYRaVtUK3oagTMPJaPyqeQHAsMqi392PyDHuHPyQlKwyln k9N1kZ2Y2okhxvpefv/6DQv7noY59HoqFTpISZkVoHJ/sb+1DzSpUHw8qKGUDWdQY8P5 H6Gi8OJ0sonaY5kjl9t9LwvmlrDTREsIgdFeulZLqMKEbL3YQQvyEDQzKYRXvTXXTiew /RIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ODfyDhzVBXotG8zgG2GcMb0+UhfaPDC8syC0S1M9rlE=; b=PQxctr20x69xuZ9WzmUjzuUAqJXE6a2tZbrFucgIAmw6Vdq3f5HcBbghyTbalDHPAg XDkW2y9Jlo4ZfM3d1LgpOKGe7M2TH1M2p6jL16PwFME9OrGfdYUGN14D5X5s0VsJkOn7 ZId2d1p7dof3A1PRuPA8L6GJ0cZ/T/46xnoZP+LWwffSy6dHbG/m08winr0UaXnGVOwU G/VXyuqUOnGIJyghikHnG0vnB8PSBd5SOnoVqxltbgWhw+TN99bcMKYpqcnAOqVVZNKb AMd3hxT/gi5XOmVoUBLKP4WY4VOZNw5wlgXsIBuGgEfbl60ZC3PTcydPLDT8RyfEpH6w ccSg== X-Gm-Message-State: APjAAAVoEBQXUCTqSczhJEuPDu4S9A7fXIglm2BjqKjpB032k++mmCKU MLbgEprAK3x6W1DpDC4zv36PMBh2 X-Google-Smtp-Source: APXvYqyTdUjiqoM2onbXeHQ2a6NprWRCiw7eWpUv2+LWAiGo7wXeoY5Nfapgu+7cAPGicuETaZX8Eg== X-Received: by 2002:a1c:a745:: with SMTP id q66mr38571252wme.167.1578405369653; Tue, 07 Jan 2020 05:56:09 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08bbf.dynamic.kabel-deutschland.de. [188.192.139.191]) by smtp.gmail.com with ESMTPSA id e18sm76167730wrr.95.2020.01.07.05.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2020 05:56:09 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Jan 2020 14:55:40 +0100 Message-Id: <20200107135549.22581-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200107135549.22581-1-andreas.rheinhardt@gmail.com> References: <20200107135549.22581-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/11] avformat: Remove unnecessary av_packet_unref() 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Since bae8844e the packet will always be unreferenced when a demuxer returns an error, so that a lot of calls to av_packet_unref() in lots of demuxers are now redundant and can be removed. Signed-off-by: Andreas Rheinhardt --- libavformat/aacdec.c | 6 ------ libavformat/adp.c | 1 - libavformat/adxdec.c | 2 -- libavformat/amr.c | 1 - libavformat/ape.c | 1 - libavformat/avs.c | 1 - libavformat/brstm.c | 3 +-- libavformat/c93.c | 13 +++---------- libavformat/cdxl.c | 1 - libavformat/concatdec.c | 4 +--- libavformat/dfa.c | 3 --- libavformat/dsicin.c | 1 - libavformat/dss.c | 6 +----- libavformat/dxa.c | 1 - libavformat/electronicarts.c | 3 --- libavformat/fitsdec.c | 2 -- libavformat/flic.c | 3 +-- libavformat/g723_1.c | 1 - libavformat/gdv.c | 1 - libavformat/gsmdec.c | 1 - libavformat/hls.c | 1 - libavformat/icodec.c | 1 - libavformat/idcin.c | 2 -- libavformat/idroqdec.c | 3 +-- libavformat/ilbc.c | 1 - libavformat/img2dec.c | 1 - libavformat/iv8.c | 1 - libavformat/libmodplug.c | 1 - libavformat/lxfdec.c | 1 - libavformat/mov.c | 1 - libavformat/mpc.c | 1 - libavformat/mpegts.c | 1 - libavformat/mpjpegdec.c | 2 -- libavformat/ncdec.c | 1 - libavformat/nuv.c | 1 - libavformat/oggdec.c | 7 ++----- libavformat/redspark.c | 1 - libavformat/rl2.c | 1 - libavformat/rpl.c | 2 -- libavformat/s337m.c | 2 -- libavformat/sapdec.c | 1 - libavformat/sdr2.c | 1 - libavformat/sierravmd.c | 1 - libavformat/siff.c | 1 - libavformat/spdifdec.c | 5 +---- libavformat/swfdec.c | 3 --- libavformat/thp.c | 2 -- libavformat/vivo.c | 14 +++++--------- libavformat/vpk.c | 4 +--- libavformat/vqf.c | 1 - libavformat/wvdec.c | 4 ---- libavformat/yuv4mpegdec.c | 1 - 52 files changed, 17 insertions(+), 108 deletions(-) diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c index 00ca2319ca..ba3f5ccc6d 100644 --- a/libavformat/aacdec.c +++ b/libavformat/aacdec.c @@ -141,7 +141,6 @@ static int handle_id3(AVFormatContext *s, AVPacket *pkt) ret = av_append_packet(s->pb, pkt, ff_id3v2_tag_len(pkt->data) - pkt->size); if (ret < 0) { - av_packet_unref(pkt); return ret; } @@ -174,7 +173,6 @@ retry: return ret; if (ret < ADTS_HEADER_SIZE) { - av_packet_unref(pkt); return AVERROR(EIO); } @@ -185,7 +183,6 @@ retry: av_assert2(append > 0); ret = av_append_packet(s->pb, pkt, append); if (ret != append) { - av_packet_unref(pkt); return AVERROR(EIO); } if (!ff_id3v2_match(pkt->data, ID3v2_DEFAULT_MAGIC)) { @@ -201,13 +198,10 @@ retry: fsize = (AV_RB32(pkt->data + 3) >> 13) & 0x1FFF; if (fsize < ADTS_HEADER_SIZE) { - av_packet_unref(pkt); return AVERROR_INVALIDDATA; } ret = av_append_packet(s->pb, pkt, fsize - pkt->size); - if (ret < 0) - av_packet_unref(pkt); return ret; } diff --git a/libavformat/adp.c b/libavformat/adp.c index 56f302acfd..8668c78fe4 100644 --- a/libavformat/adp.c +++ b/libavformat/adp.c @@ -78,7 +78,6 @@ static int adp_read_packet(AVFormatContext *s, AVPacket *pkt) if (ret != size) { if (ret < 0) { - av_packet_unref(pkt); return ret; } av_shrink_packet(pkt, ret); diff --git a/libavformat/adxdec.c b/libavformat/adxdec.c index f80b4b80f0..ccd5049acd 100644 --- a/libavformat/adxdec.c +++ b/libavformat/adxdec.c @@ -65,11 +65,9 @@ static int adx_read_packet(AVFormatContext *s, AVPacket *pkt) ret = av_get_packet(s->pb, pkt, size); if (ret != size) { - av_packet_unref(pkt); return ret < 0 ? ret : AVERROR(EIO); } if (AV_RB16(pkt->data) & 0x8000) { - av_packet_unref(pkt); return AVERROR_EOF; } pkt->size = size; diff --git a/libavformat/amr.c b/libavformat/amr.c index 42840a50a3..b19ad18e04 100644 --- a/libavformat/amr.c +++ b/libavformat/amr.c @@ -154,7 +154,6 @@ static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) read = avio_read(s->pb, pkt->data + 1, size - 1); if (read != size - 1) { - av_packet_unref(pkt); if (read < 0) return read; return AVERROR(EIO); diff --git a/libavformat/ape.c b/libavformat/ape.c index e31a00dc96..ed6752a415 100644 --- a/libavformat/ape.c +++ b/libavformat/ape.c @@ -419,7 +419,6 @@ static int ape_read_packet(AVFormatContext * s, AVPacket * pkt) AV_WL32(pkt->data + 4, ape->frames[ape->currentframe].skip); ret = avio_read(s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size); if (ret < 0) { - av_packet_unref(pkt); return ret; } diff --git a/libavformat/avs.c b/libavformat/avs.c index 47fa41017d..3a2d84aa19 100644 --- a/libavformat/avs.c +++ b/libavformat/avs.c @@ -114,7 +114,6 @@ avs_read_video_packet(AVFormatContext * s, AVPacket * pkt, pkt->data[palette_size + 3] = (size >> 8) & 0xFF; ret = avio_read(s->pb, pkt->data + palette_size + 4, size - 4) + 4; if (ret < size) { - av_packet_unref(pkt); return AVERROR(EIO); } diff --git a/libavformat/brstm.c b/libavformat/brstm.c index 1470690731..ca965ed7e1 100644 --- a/libavformat/brstm.c +++ b/libavformat/brstm.c @@ -422,8 +422,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) dst += size; avio_skip(s->pb, skip); if (ret != size) { - av_packet_unref(pkt); - break; + return AVERROR(EIO); } } pkt->duration = samples; diff --git a/libavformat/c93.c b/libavformat/c93.c index 8aa80b5e0b..256b9800ca 100644 --- a/libavformat/c93.c +++ b/libavformat/c93.c @@ -158,22 +158,19 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) ret = avio_read(pb, pkt->data + 1, datasize); if (ret < datasize) { - ret = AVERROR(EIO); - goto fail; + return AVERROR(EIO); } datasize = avio_rl16(pb); /* palette size */ if (datasize) { if (datasize != 768) { av_log(s, AV_LOG_ERROR, "invalid palette size %u\n", datasize); - ret = AVERROR_INVALIDDATA; - goto fail; + return AVERROR_INVALIDDATA; } pkt->data[0] |= C93_HAS_PALETTE; ret = avio_read(pb, pkt->data + pkt->size, datasize); if (ret < datasize) { - ret = AVERROR(EIO); - goto fail; + return AVERROR(EIO); } pkt->size += 768; } @@ -186,10 +183,6 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) pkt->data[0] |= C93_FIRST_FRAME; } return 0; - - fail: - av_packet_unref(pkt); - return ret; } AVInputFormat ff_c93_demuxer = { diff --git a/libavformat/cdxl.c b/libavformat/cdxl.c index 31f7cb823a..5718fc3e21 100644 --- a/libavformat/cdxl.c +++ b/libavformat/cdxl.c @@ -207,7 +207,6 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) memcpy(pkt->data, cdxl->header, CDXL_HEADER_SIZE); ret = avio_read(pb, pkt->data + CDXL_HEADER_SIZE, video_size); if (ret < 0) { - av_packet_unref(pkt); return ret; } av_shrink_packet(pkt, CDXL_HEADER_SIZE + ret); diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index e826821241..2173911ce4 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -542,7 +542,6 @@ static int filter_packet(AVFormatContext *avf, ConcatStream *cs, AVPacket *pkt) if (ret < 0) { av_log(avf, AV_LOG_ERROR, "h264_mp4toannexb filter " "failed to send input packet\n"); - av_packet_unref(pkt); return ret; } @@ -592,7 +591,6 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt) if (ret < 0) return ret; if ((ret = match_streams(avf)) < 0) { - av_packet_unref(pkt); return ret; } if (packet_after_outpoint(cat, pkt)) { @@ -608,7 +606,7 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt) } break; } - if ((ret = filter_packet(avf, cs, pkt))) + if ((ret = filter_packet(avf, cs, pkt)) < 0) return ret; st = cat->avf->streams[pkt->stream_index]; diff --git a/libavformat/dfa.c b/libavformat/dfa.c index d667cd6277..bd4ef2dafe 100644 --- a/libavformat/dfa.c +++ b/libavformat/dfa.c @@ -93,7 +93,6 @@ static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt) if (!first) { ret = av_append_packet(pb, pkt, 12); if (ret < 0) { - av_packet_unref(pkt); return ret; } } else @@ -101,7 +100,6 @@ static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt) frame_size = AV_RL32(pkt->data + pkt->size - 8); if (frame_size > INT_MAX - 4) { av_log(s, AV_LOG_ERROR, "Too large chunk size: %"PRIu32"\n", frame_size); - av_packet_unref(pkt); return AVERROR(EIO); } if (AV_RL32(pkt->data + pkt->size - 12) == MKTAG('E', 'O', 'F', 'R')) { @@ -115,7 +113,6 @@ static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt) } ret = av_append_packet(pb, pkt, frame_size); if (ret < 0) { - av_packet_unref(pkt); return ret; } } diff --git a/libavformat/dsicin.c b/libavformat/dsicin.c index 244622ee39..b18f43b9a0 100644 --- a/libavformat/dsicin.c +++ b/libavformat/dsicin.c @@ -200,7 +200,6 @@ static int cin_read_packet(AVFormatContext *s, AVPacket *pkt) ret = avio_read(pb, &pkt->data[4], pkt_size); if (ret < 0) { - av_packet_unref(pkt); return ret; } if (ret < pkt_size) diff --git a/libavformat/dss.c b/libavformat/dss.c index d7f9cafe47..8e0b72fbe5 100644 --- a/libavformat/dss.c +++ b/libavformat/dss.c @@ -259,14 +259,12 @@ static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt) dss_sp_byte_swap(ctx, pkt->data, ctx->dss_sp_buf); if (ctx->dss_sp_swap_byte < 0) { - ret = AVERROR(EAGAIN); - goto error_eof; + return AVERROR(EAGAIN); } return pkt->size; error_eof: - av_packet_unref(pkt); return ret < 0 ? ret : AVERROR_EOF; } @@ -308,7 +306,6 @@ static int dss_723_1_read_packet(AVFormatContext *s, AVPacket *pkt) ret = avio_read(s->pb, pkt->data + offset, size2 - offset); if (ret < size2 - offset) { - av_packet_unref(pkt); return ret < 0 ? ret : AVERROR_EOF; } @@ -318,7 +315,6 @@ static int dss_723_1_read_packet(AVFormatContext *s, AVPacket *pkt) ret = avio_read(s->pb, pkt->data + offset, size - offset); if (ret < size - offset) { - av_packet_unref(pkt); return ret < 0 ? ret : AVERROR_EOF; } diff --git a/libavformat/dxa.c b/libavformat/dxa.c index 994078e633..27fa6afb6a 100644 --- a/libavformat/dxa.c +++ b/libavformat/dxa.c @@ -210,7 +210,6 @@ static int dxa_read_packet(AVFormatContext *s, AVPacket *pkt) memcpy(pkt->data + pal_size, buf, DXA_EXTRA_SIZE); ret = avio_read(s->pb, pkt->data + DXA_EXTRA_SIZE + pal_size, size); if(ret != size){ - av_packet_unref(pkt); return AVERROR(EIO); } if(pal_size) memcpy(pkt->data, pal, pal_size); diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c index c894663c29..2ee5e1b6fa 100644 --- a/libavformat/electronicarts.c +++ b/libavformat/electronicarts.c @@ -633,7 +633,6 @@ static int ea_read_packet(AVFormatContext *s, AVPacket *pkt) case AV_CODEC_ID_ADPCM_EA_R3: if (pkt->size < 4) { av_log(s, AV_LOG_ERROR, "Packet is too short\n"); - av_packet_unref(pkt); return AVERROR_INVALIDDATA; } if (ea->audio_codec == AV_CODEC_ID_ADPCM_EA_R3) @@ -736,8 +735,6 @@ get_video_packet: } } - if (ret < 0 && partial_packet) - av_packet_unref(pkt); if (ret >= 0 && hit_end && !packet_read) return AVERROR(EAGAIN); diff --git a/libavformat/fitsdec.c b/libavformat/fitsdec.c index c7d1edec60..e917fc2375 100644 --- a/libavformat/fitsdec.c +++ b/libavformat/fitsdec.c @@ -183,7 +183,6 @@ static int fits_read_packet(AVFormatContext *s, AVPacket *pkt) ret = av_bprint_finalize(&avbuf, &buf); if (ret < 0) { - av_packet_unref(pkt); return ret; } @@ -192,7 +191,6 @@ static int fits_read_packet(AVFormatContext *s, AVPacket *pkt) av_freep(&buf); ret = avio_read(s->pb, pkt->data + pkt->size, size); if (ret < 0) { - av_packet_unref(pkt); return ret; } diff --git a/libavformat/flic.c b/libavformat/flic.c index 615d6b25c5..da7b732388 100644 --- a/libavformat/flic.c +++ b/libavformat/flic.c @@ -226,7 +226,6 @@ static int flic_read_packet(AVFormatContext *s, ret = avio_read(pb, pkt->data + FLIC_PREAMBLE_SIZE, size - FLIC_PREAMBLE_SIZE); if (ret != size - FLIC_PREAMBLE_SIZE) { - av_packet_unref(pkt); ret = AVERROR(EIO); } packet_read = 1; @@ -244,8 +243,8 @@ static int flic_read_packet(AVFormatContext *s, ret = avio_read(pb, pkt->data, size); if (ret != size) { - av_packet_unref(pkt); ret = AVERROR(EIO); + break; } packet_read = 1; diff --git a/libavformat/g723_1.c b/libavformat/g723_1.c index 27c8c3951b..3af4809347 100644 --- a/libavformat/g723_1.c +++ b/libavformat/g723_1.c @@ -69,7 +69,6 @@ static int g723_1_read_packet(AVFormatContext *s, AVPacket *pkt) ret = avio_read(s->pb, pkt->data + 1, size - 1); if (ret < size - 1) { - av_packet_unref(pkt); return ret < 0 ? ret : AVERROR_EOF; } diff --git a/libavformat/gdv.c b/libavformat/gdv.c index b698497a6a..2ecbb535e7 100644 --- a/libavformat/gdv.c +++ b/libavformat/gdv.c @@ -182,7 +182,6 @@ static int gdv_read_packet(AVFormatContext *ctx, AVPacket *pkt) pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE); if (!pal) { - av_packet_unref(pkt); return AVERROR(ENOMEM); } memcpy(pal, gdv->pal, AVPALETTE_SIZE); diff --git a/libavformat/gsmdec.c b/libavformat/gsmdec.c index 1044cde317..ec6b2e924f 100644 --- a/libavformat/gsmdec.c +++ b/libavformat/gsmdec.c @@ -62,7 +62,6 @@ static int gsm_read_packet(AVFormatContext *s, AVPacket *pkt) ret = av_get_packet(s->pb, pkt, size); if (ret < GSM_BLOCK_SIZE) { - av_packet_unref(pkt); return ret < 0 ? ret : AVERROR(EIO); } pkt->duration = 1; diff --git a/libavformat/hls.c b/libavformat/hls.c index 538af0dbf8..5766857303 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -2214,7 +2214,6 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt) if (ist->codecpar->codec_id != st->codecpar->codec_id) { ret = set_stream_info_from_input_stream(st, pls, ist); if (ret < 0) { - av_packet_unref(pkt); return ret; } } diff --git a/libavformat/icodec.c b/libavformat/icodec.c index 98684e5e74..b47fa98f80 100644 --- a/libavformat/icodec.c +++ b/libavformat/icodec.c @@ -185,7 +185,6 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) bytestream_put_le32(&buf, 0); if ((ret = avio_read(pb, buf, image->size)) != image->size) { - av_packet_unref(pkt); return ret < 0 ? ret : AVERROR_INVALIDDATA; } diff --git a/libavformat/idcin.c b/libavformat/idcin.c index 0b1058171b..5a6a15aa81 100644 --- a/libavformat/idcin.c +++ b/libavformat/idcin.c @@ -313,7 +313,6 @@ static int idcin_read_packet(AVFormatContext *s, return ret; else if (ret != chunk_size) { av_log(s, AV_LOG_ERROR, "incomplete packet\n"); - av_packet_unref(pkt); return AVERROR(EIO); } if (command == 1) { @@ -322,7 +321,6 @@ static int idcin_read_packet(AVFormatContext *s, pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE); if (!pal) { - av_packet_unref(pkt); return AVERROR(ENOMEM); } memcpy(pal, palette, AVPALETTE_SIZE); diff --git a/libavformat/idroqdec.c b/libavformat/idroqdec.c index 1db4cce6f0..56ab83424f 100644 --- a/libavformat/idroqdec.c +++ b/libavformat/idroqdec.c @@ -223,8 +223,7 @@ static int roq_read_packet(AVFormatContext *s, ret = avio_read(pb, pkt->data + RoQ_CHUNK_PREAMBLE_SIZE, chunk_size); if (ret != chunk_size) { - av_packet_unref(pkt); - ret = AVERROR(EIO); + return AVERROR(EIO); } packet_read = 1; diff --git a/libavformat/ilbc.c b/libavformat/ilbc.c index ba11953b59..95a631158d 100644 --- a/libavformat/ilbc.c +++ b/libavformat/ilbc.c @@ -112,7 +112,6 @@ static int ilbc_read_packet(AVFormatContext *s, pkt->pos = avio_tell(s->pb); pkt->duration = par->block_align == 38 ? 160 : 240; if ((ret = avio_read(s->pb, pkt->data, par->block_align)) != par->block_align) { - av_packet_unref(pkt); return ret < 0 ? ret : AVERROR(EIO); } diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index f8b4a655a5..1739628bac 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -504,7 +504,6 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt) } if (ret[0] <= 0 || ret[1] < 0 || ret[2] < 0) { - av_packet_unref(pkt); if (ret[0] < 0) { res = ret[0]; } else if (ret[1] < 0) { diff --git a/libavformat/iv8.c b/libavformat/iv8.c index 449a422347..e25f24eeb9 100644 --- a/libavformat/iv8.c +++ b/libavformat/iv8.c @@ -92,7 +92,6 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) ret = av_append_packet(s->pb, pkt, size); if (ret < 0) { av_log(s, AV_LOG_ERROR, "failed to grow packet\n"); - av_packet_unref(pkt); return ret; } } diff --git a/libavformat/libmodplug.c b/libavformat/libmodplug.c index 6a32618e6f..6e567f5f98 100644 --- a/libavformat/libmodplug.c +++ b/libavformat/libmodplug.c @@ -327,7 +327,6 @@ static int modplug_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->size = ModPlug_Read(modplug->f, pkt->data, AUDIO_PKT_SIZE); if (pkt->size <= 0) { - av_packet_unref(pkt); return pkt->size == 0 ? AVERROR_EOF : AVERROR(EIO); } return 0; diff --git a/libavformat/lxfdec.c b/libavformat/lxfdec.c index 434518fc59..fa84ceea78 100644 --- a/libavformat/lxfdec.c +++ b/libavformat/lxfdec.c @@ -316,7 +316,6 @@ static int lxf_read_packet(AVFormatContext *s, AVPacket *pkt) return ret2; if ((ret2 = avio_read(pb, pkt->data, ret)) != ret) { - av_packet_unref(pkt); return ret2 < 0 ? ret2 : AVERROR_EOF; } diff --git a/libavformat/mov.c b/libavformat/mov.c index 890c6e85b8..3dcd458fd3 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7882,7 +7882,6 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) ret = cenc_filter(mov, st, sc, pkt, current_index); if (ret < 0) { - av_packet_unref(pkt); return ret; } diff --git a/libavformat/mpc.c b/libavformat/mpc.c index a7b2e116ed..85036cd118 100644 --- a/libavformat/mpc.c +++ b/libavformat/mpc.c @@ -169,7 +169,6 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt) if(c->curbits) avio_seek(s->pb, -4, SEEK_CUR); if(ret < size){ - av_packet_unref(pkt); return ret < 0 ? ret : AVERROR(EIO); } pkt->size = ret + 4; diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 5c850bc1e5..a90900127c 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -3133,7 +3133,6 @@ static int mpegts_raw_read_packet(AVFormatContext *s, AVPacket *pkt) ret = read_packet(s, pkt->data, ts->raw_packet_size, &data); pkt->pos = avio_tell(s->pb); if (ret < 0) { - av_packet_unref(pkt); return ret; } if (data != pkt->data) diff --git a/libavformat/mpjpegdec.c b/libavformat/mpjpegdec.c index c79a39c69d..1e2ab0db1a 100644 --- a/libavformat/mpjpegdec.c +++ b/libavformat/mpjpegdec.c @@ -359,8 +359,6 @@ static int mpjpeg_read_packet(AVFormatContext *s, AVPacket *pkt) /* error or EOF occurred */ if (ret == AVERROR_EOF) { ret = pkt->size > 0 ? pkt->size : AVERROR_EOF; - } else { - av_packet_unref(pkt); } } diff --git a/libavformat/ncdec.c b/libavformat/ncdec.c index bc3d3e82bf..f2066b485a 100644 --- a/libavformat/ncdec.c +++ b/libavformat/ncdec.c @@ -83,7 +83,6 @@ static int nc_read_packet(AVFormatContext *s, AVPacket *pkt) ret = av_get_packet(s->pb, pkt, size); if (ret != size) { - if (ret > 0) av_packet_unref(pkt); return AVERROR(EIO); } diff --git a/libavformat/nuv.c b/libavformat/nuv.c index bef0ae4860..d99770d41d 100644 --- a/libavformat/nuv.c +++ b/libavformat/nuv.c @@ -284,7 +284,6 @@ static int nuv_packet(AVFormatContext *s, AVPacket *pkt) memcpy(pkt->data, hdr, copyhdrsize); ret = avio_read(pb, pkt->data + copyhdrsize, size); if (ret < 0) { - av_packet_unref(pkt); return ret; } if (ret < size) diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c index e815f42134..4f4b5fe386 100644 --- a/libavformat/oggdec.c +++ b/libavformat/oggdec.c @@ -851,7 +851,7 @@ retry: AV_PKT_DATA_SKIP_SAMPLES, 10); if(!side_data) - goto fail; + return AVERROR(ENOMEM); AV_WL32(side_data + 4, os->end_trimming); os->end_trimming = 0; } @@ -861,7 +861,7 @@ retry: AV_PKT_DATA_METADATA_UPDATE, os->new_metadata_size); if(!side_data) - goto fail; + return AVERROR(ENOMEM); memcpy(side_data, os->new_metadata, os->new_metadata_size); av_freep(&os->new_metadata); @@ -869,9 +869,6 @@ retry: } return psize; -fail: - av_packet_unref(pkt); - return AVERROR(ENOMEM); } static int64_t ogg_read_timestamp(AVFormatContext *s, int stream_index, diff --git a/libavformat/redspark.c b/libavformat/redspark.c index f1f2b3156d..0ce8915311 100644 --- a/libavformat/redspark.c +++ b/libavformat/redspark.c @@ -140,7 +140,6 @@ static int redspark_read_packet(AVFormatContext *s, AVPacket *pkt) ret = av_get_packet(s->pb, pkt, size); if (ret != size) { - av_packet_unref(pkt); return AVERROR(EIO); } diff --git a/libavformat/rl2.c b/libavformat/rl2.c index 9e10155838..cfde23a945 100644 --- a/libavformat/rl2.c +++ b/libavformat/rl2.c @@ -256,7 +256,6 @@ static int rl2_read_packet(AVFormatContext *s, /** fill the packet */ ret = av_get_packet(pb, pkt, sample->size); if(ret != sample->size){ - av_packet_unref(pkt); return AVERROR(EIO); } diff --git a/libavformat/rpl.c b/libavformat/rpl.c index 6afd373810..208c50f00c 100644 --- a/libavformat/rpl.c +++ b/libavformat/rpl.c @@ -338,7 +338,6 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt) if (ret < 0) return ret; if (ret != frame_size) { - av_packet_unref(pkt); return AVERROR(EIO); } pkt->duration = 1; @@ -355,7 +354,6 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt) if (ret < 0) return ret; if (ret != index_entry->size) { - av_packet_unref(pkt); return AVERROR(EIO); } diff --git a/libavformat/s337m.c b/libavformat/s337m.c index 48ab66a6da..d7d9b4ce88 100644 --- a/libavformat/s337m.c +++ b/libavformat/s337m.c @@ -174,7 +174,6 @@ static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->pos = pos; if (avio_read(pb, pkt->data, pkt->size) < pkt->size) { - av_packet_unref(pkt); return AVERROR_EOF; } @@ -186,7 +185,6 @@ static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) if (!s->nb_streams) { AVStream *st = avformat_new_stream(s, NULL); if (!st) { - av_packet_unref(pkt); return AVERROR(ENOMEM); } st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; diff --git a/libavformat/sapdec.c b/libavformat/sapdec.c index f8bc0d281c..b3644b436b 100644 --- a/libavformat/sapdec.c +++ b/libavformat/sapdec.c @@ -225,7 +225,6 @@ static int sap_fetch_packet(AVFormatContext *s, AVPacket *pkt) int i = s->nb_streams; AVStream *st = avformat_new_stream(s, NULL); if (!st) { - av_packet_unref(pkt); return AVERROR(ENOMEM); } st->id = i; diff --git a/libavformat/sdr2.c b/libavformat/sdr2.c index 8893f260d2..3743d59e58 100644 --- a/libavformat/sdr2.c +++ b/libavformat/sdr2.c @@ -95,7 +95,6 @@ static int sdr2_read_packet(AVFormatContext *s, AVPacket *pkt) memcpy(pkt->data, header, 24); ret = avio_read(s->pb, pkt->data + 24, next - 52); if (ret < 0) { - av_packet_unref(pkt); return ret; } av_shrink_packet(pkt, ret + 24); diff --git a/libavformat/sierravmd.c b/libavformat/sierravmd.c index 8c2322eda6..531fc41531 100644 --- a/libavformat/sierravmd.c +++ b/libavformat/sierravmd.c @@ -295,7 +295,6 @@ static int vmd_read_packet(AVFormatContext *s, frame->frame_size); if (ret != frame->frame_size) { - av_packet_unref(pkt); ret = AVERROR(EIO); } pkt->stream_index = frame->stream_index; diff --git a/libavformat/siff.c b/libavformat/siff.c index 56c5b33c76..f6815b2f26 100644 --- a/libavformat/siff.c +++ b/libavformat/siff.c @@ -220,7 +220,6 @@ static int siff_read_packet(AVFormatContext *s, AVPacket *pkt) if (c->gmcsize) memcpy(pkt->data + 2, c->gmc, c->gmcsize); if (avio_read(s->pb, pkt->data + 2 + c->gmcsize, size) != size) { - av_packet_unref(pkt); return AVERROR_INVALIDDATA; } pkt->stream_index = 0; diff --git a/libavformat/spdifdec.c b/libavformat/spdifdec.c index d74f58d82b..1808fa9d65 100644 --- a/libavformat/spdifdec.c +++ b/libavformat/spdifdec.c @@ -197,15 +197,13 @@ int ff_spdif_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->pos = avio_tell(pb) - BURST_HEADER_SIZE; if (avio_read(pb, pkt->data, pkt->size) < pkt->size) { - av_packet_unref(pkt); return AVERROR_EOF; } ff_spdif_bswap_buf16((uint16_t *)pkt->data, (uint16_t *)pkt->data, pkt->size >> 1); ret = spdif_get_offset_and_codec(s, data_type, pkt->data, &offset, &codec_id); - if (ret) { - av_packet_unref(pkt); + if (ret < 0) { return ret; } @@ -216,7 +214,6 @@ int ff_spdif_read_packet(AVFormatContext *s, AVPacket *pkt) /* first packet, create a stream */ AVStream *st = avformat_new_stream(s, NULL); if (!st) { - av_packet_unref(pkt); return AVERROR(ENOMEM); } st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c index a9358f09a9..9a0b27bd8c 100644 --- a/libavformat/swfdec.c +++ b/libavformat/swfdec.c @@ -399,7 +399,6 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) if (linesize * height > pkt->size) { res = AVERROR_INVALIDDATA; - av_packet_unref(pkt); goto bitmap_end; } @@ -489,7 +488,6 @@ bitmap_end_skip: if ((res = av_new_packet(pkt, len)) < 0) return res; if (avio_read(pb, pkt->data, 4) != 4) { - av_packet_unref(pkt); return AVERROR_INVALIDDATA; } if (AV_RB32(pkt->data) == 0xffd8ffd9 || @@ -506,7 +504,6 @@ bitmap_end_skip: } if (res != pkt->size) { if (res < 0) { - av_packet_unref(pkt); return res; } av_shrink_packet(pkt, res); diff --git a/libavformat/thp.c b/libavformat/thp.c index ee5c78b6d3..332ed79128 100644 --- a/libavformat/thp.c +++ b/libavformat/thp.c @@ -181,7 +181,6 @@ static int thp_read_packet(AVFormatContext *s, if (ret < 0) return ret; if (ret != size) { - av_packet_unref(pkt); return AVERROR(EIO); } @@ -191,7 +190,6 @@ static int thp_read_packet(AVFormatContext *s, if (ret < 0) return ret; if (ret != thp->audiosize) { - av_packet_unref(pkt); return AVERROR(EIO); } diff --git a/libavformat/vivo.c b/libavformat/vivo.c index 9a07c43849..4039cd0fe5 100644 --- a/libavformat/vivo.c +++ b/libavformat/vivo.c @@ -273,32 +273,28 @@ restart: } if ((ret = av_get_packet(pb, pkt, vivo->length)) < 0) - goto fail; + return ret; // get next packet header if ((ret = vivo_get_packet_header(s)) < 0) - goto fail; + return ret; while (vivo->sequence == old_sequence && (((vivo->type - 1) >> 1) == ((old_type - 1) >> 1))) { if (avio_feof(pb)) { - ret = AVERROR_EOF; - break; + return AVERROR_EOF; } if ((ret = av_append_packet(pb, pkt, vivo->length)) < 0) - break; + return ret; // get next packet header if ((ret = vivo_get_packet_header(s)) < 0) - break; + return ret; } pkt->stream_index = stream_index; -fail: - if (ret < 0) - av_packet_unref(pkt); return ret; } diff --git a/libavformat/vpk.c b/libavformat/vpk.c index 255d6030b0..dd9aeb6101 100644 --- a/libavformat/vpk.c +++ b/libavformat/vpk.c @@ -93,9 +93,7 @@ static int vpk_read_packet(AVFormatContext *s, AVPacket *pkt) ret = avio_read(s->pb, pkt->data + i * size, size); avio_skip(s->pb, skip); if (ret != size) { - av_packet_unref(pkt); - ret = AVERROR(EIO); - break; + return AVERROR(EIO); } } pkt->stream_index = 0; diff --git a/libavformat/vqf.c b/libavformat/vqf.c index b43725b3c1..15660e9fd8 100644 --- a/libavformat/vqf.c +++ b/libavformat/vqf.c @@ -249,7 +249,6 @@ static int vqf_read_packet(AVFormatContext *s, AVPacket *pkt) ret = avio_read(s->pb, pkt->data+2, size); if (ret != size) { - av_packet_unref(pkt); return AVERROR(EIO); } diff --git a/libavformat/wvdec.c b/libavformat/wvdec.c index f2bb4c60ba..0aa581534d 100644 --- a/libavformat/wvdec.c +++ b/libavformat/wvdec.c @@ -287,25 +287,21 @@ static int wv_read_packet(AVFormatContext *s, AVPacket *pkt) memcpy(pkt->data, wc->block_header, WV_HEADER_SIZE); ret = avio_read(s->pb, pkt->data + WV_HEADER_SIZE, wc->header.blocksize); if (ret != wc->header.blocksize) { - av_packet_unref(pkt); return AVERROR(EIO); } while (!(wc->header.flags & WV_FLAG_FINAL_BLOCK)) { if ((ret = wv_read_block_header(s, s->pb)) < 0) { - av_packet_unref(pkt); return ret; } off = pkt->size; if ((ret = av_grow_packet(pkt, WV_HEADER_SIZE + wc->header.blocksize)) < 0) { - av_packet_unref(pkt); return ret; } memcpy(pkt->data + off, wc->block_header, WV_HEADER_SIZE); ret = avio_read(s->pb, pkt->data + off + WV_HEADER_SIZE, wc->header.blocksize); if (ret != wc->header.blocksize) { - av_packet_unref(pkt); return (ret < 0) ? ret : AVERROR_EOF; } } diff --git a/libavformat/yuv4mpegdec.c b/libavformat/yuv4mpegdec.c index eceb945bb1..b8e2980a3d 100644 --- a/libavformat/yuv4mpegdec.c +++ b/libavformat/yuv4mpegdec.c @@ -310,7 +310,6 @@ static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt) if (ret < 0) return ret; else if (ret != s->packet_size - Y4M_FRAME_MAGIC_LEN) { - av_packet_unref(pkt); return s->pb->eof_reached ? AVERROR_EOF : AVERROR(EIO); } pkt->stream_index = 0;