From 329333ca8b320aec397c9043a578895aef69c1eb Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 1 Jan 2018 19:16:05 -0800 Subject: [PATCH] Don't leak the AVIOContext --- examples/alffplay.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp index 12b924ae..7f0cdb1f 100644 --- a/examples/alffplay.cpp +++ b/examples/alffplay.cpp @@ -86,6 +86,11 @@ inline microseconds get_avtime() { return microseconds(av_gettime()); } /* Define unique_ptrs to auto-cleanup associated ffmpeg objects. */ +struct AVIOContextDeleter { + void operator()(AVIOContext *ptr) { avio_closep(&ptr); } +}; +using AVIOContextPtr = std::unique_ptr; + struct AVFormatCtxDeleter { void operator()(AVFormatContext *ptr) { avformat_close_input(&ptr); } }; @@ -270,6 +275,7 @@ struct VideoState { }; struct MovieState { + AVIOContextPtr mIOContext; AVFormatCtxPtr mFormatCtx; SyncMaster mAVSyncType{SyncMaster::Default}; @@ -1132,12 +1138,13 @@ bool MovieState::prepare() std::cerr<< "Failed to open "<pb = avioctx; + fmtctx->pb = mIOContext.get(); fmtctx->interrupt_callback = intcb; if(avformat_open_input(&fmtctx, mFilename.c_str(), nullptr, nullptr) != 0) {