From 8e32b1f0963d01d4f5d4803eb721f162e0d58d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 24 Feb 2015 14:07:54 +0200 Subject: [PATCH] libavformat: Use ffio_free_dyn_buf where applicable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/dashenc.c | 3 +-- libavformat/id3v2.c | 8 ++++---- libavformat/movenchint.c | 4 +--- libavformat/mpegtsenc.c | 5 ++--- libavformat/nutenc.c | 11 +++-------- libavformat/rtpenc_chain.c | 4 +--- libavformat/rtpenc_mpegts.c | 13 +++---------- libavformat/rtsp.c | 4 +--- 8 files changed, 16 insertions(+), 36 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index d715654ca7..25766155bf 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -155,8 +155,7 @@ static void set_codec_str(AVFormatContext *s, AVCodecContext *codec, if (avio_open_dyn_buf(&pb) < 0) return; if (ff_isom_write_avcc(pb, extradata, extradata_size) < 0) { - avio_close_dyn_buf(pb, &tmpbuf); - av_free(tmpbuf); + ffio_free_dyn_buf(&pb); return; } extradata_size = avio_close_dyn_buf(pb, &extradata); diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c index 3c5c06207f..b8994b2226 100644 --- a/libavformat/id3v2.c +++ b/libavformat/id3v2.c @@ -207,8 +207,8 @@ static int decode_str(AVFormatContext *s, AVIOContext *pb, int encoding, case ID3v2_ENCODING_UTF16BOM: if ((left -= 2) < 0) { av_log(s, AV_LOG_ERROR, "Cannot read BOM value, input too short\n"); - avio_close_dyn_buf(dynbuf, dst); - av_freep(dst); + ffio_free_dyn_buf(&dynbuf); + *dst = NULL; return AVERROR_INVALIDDATA; } switch (avio_rb16(pb)) { @@ -218,8 +218,8 @@ static int decode_str(AVFormatContext *s, AVIOContext *pb, int encoding, break; default: av_log(s, AV_LOG_ERROR, "Incorrect BOM value\n"); - avio_close_dyn_buf(dynbuf, dst); - av_freep(dst); + ffio_free_dyn_buf(&dynbuf); + *dst = NULL; *maxread = left; return AVERROR_INVALIDDATA; } diff --git a/libavformat/movenchint.c b/libavformat/movenchint.c index a8f5f34f9c..73498e4547 100644 --- a/libavformat/movenchint.c +++ b/libavformat/movenchint.c @@ -458,7 +458,6 @@ done: void ff_mov_close_hinting(MOVTrack *track) { AVFormatContext *rtp_ctx = track->rtp_ctx; - uint8_t *ptr; av_freep(&track->enc); sample_queue_free(&track->sample_queue); @@ -466,8 +465,7 @@ void ff_mov_close_hinting(MOVTrack *track) return; if (rtp_ctx->pb) { av_write_trailer(rtp_ctx); - avio_close_dyn_buf(rtp_ctx->pb, &ptr); - av_free(ptr); + ffio_free_dyn_buf(&rtp_ctx->pb); } avformat_free_context(rtp_ctx); } diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 1be4e55683..de6e6acab6 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -29,6 +29,7 @@ #include "libavcodec/internal.h" #include "avformat.h" +#include "avio_internal.h" #include "internal.h" #include "mpegts.h" @@ -1110,9 +1111,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) ret = av_write_frame(ts_st->amux, &pkt2); if (ret < 0) { - avio_close_dyn_buf(ts_st->amux->pb, &data); - ts_st->amux->pb = NULL; - av_free(data); + ffio_free_dyn_buf(&ts_st->amux->pb); return ret; } size = avio_close_dyn_buf(ts_st->amux->pb, &data); diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index 3b43954dbd..b7b0c9c790 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -616,11 +616,8 @@ static int write_headers(AVFormatContext *avctx, AVIOContext *bc) return ret; if (ret > 0) put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE); - else { - uint8_t *buf; - avio_close_dyn_buf(dyn_bc, &buf); - av_free(buf); - } + else + ffio_free_dyn_buf(&dyn_bc); } for (i = 0; i < nut->avf->nb_chapters; i++) { @@ -629,9 +626,7 @@ static int write_headers(AVFormatContext *avctx, AVIOContext *bc) return ret; ret = write_chapter(nut, dyn_bc, i); if (ret < 0) { - uint8_t *buf; - avio_close_dyn_buf(dyn_bc, &buf); - av_freep(&buf); + ffio_free_dyn_buf(&dyn_bc); return ret; } put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE); diff --git a/libavformat/rtpenc_chain.c b/libavformat/rtpenc_chain.c index 773a7dbbc8..e58eb545b8 100644 --- a/libavformat/rtpenc_chain.c +++ b/libavformat/rtpenc_chain.c @@ -89,9 +89,7 @@ int ff_rtp_chain_mux_open(AVFormatContext **out, AVFormatContext *s, if (handle && rtpctx->pb) { avio_close(rtpctx->pb); } else if (rtpctx->pb) { - uint8_t *ptr; - avio_close_dyn_buf(rtpctx->pb, &ptr); - av_free(ptr); + ffio_free_dyn_buf(&rtpctx->pb); } avformat_free_context(rtpctx); return ret; diff --git a/libavformat/rtpenc_mpegts.c b/libavformat/rtpenc_mpegts.c index f170f97934..8ad446b9dd 100644 --- a/libavformat/rtpenc_mpegts.c +++ b/libavformat/rtpenc_mpegts.c @@ -21,6 +21,7 @@ #include "libavutil/mathematics.h" #include "avformat.h" +#include "avio_internal.h" struct MuxChain { AVFormatContext *mpegts_ctx; @@ -33,11 +34,7 @@ static int rtp_mpegts_write_close(AVFormatContext *s) if (chain->mpegts_ctx) { av_write_trailer(chain->mpegts_ctx); - if (chain->mpegts_ctx->pb) { - uint8_t *buf; - avio_close_dyn_buf(chain->mpegts_ctx->pb, &buf); - av_free(buf); - } + ffio_free_dyn_buf(&chain->mpegts_ctx->pb); avformat_free_context(chain->mpegts_ctx); } if (chain->rtp_ctx) { @@ -101,11 +98,7 @@ static int rtp_mpegts_write_header(AVFormatContext *s) fail: if (mpegts_ctx) { - if (mpegts_ctx->pb) { - uint8_t *buf; - avio_close_dyn_buf(mpegts_ctx->pb, &buf); - av_free(buf); - } + ffio_free_dyn_buf(&chain->mpegts_ctx->pb); avformat_free_context(mpegts_ctx); } if (rtp_ctx) diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 49a89dfae8..f7b7b32851 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -703,11 +703,9 @@ void ff_rtsp_undo_setup(AVFormatContext *s, int send_packets) AVFormatContext *rtpctx = rtsp_st->transport_priv; av_write_trailer(rtpctx); if (rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP) { - uint8_t *ptr; if (CONFIG_RTSP_MUXER && rtpctx->pb && send_packets) ff_rtsp_tcp_write_packet(s, rtsp_st); - avio_close_dyn_buf(rtpctx->pb, &ptr); - av_free(ptr); + ffio_free_dyn_buf(&rtpctx->pb); } else { avio_close(rtpctx->pb); }