diff options
author | Chris Robinson <[email protected]> | 2018-01-01 19:16:05 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-01-01 19:16:05 -0800 |
commit | 329333ca8b320aec397c9043a578895aef69c1eb (patch) | |
tree | aa33dc6ef408db35b1a0953fe9ef1103b8bdead9 /examples | |
parent | 91e20dc12ef9398fea6c26d9c9987341978e4209 (diff) |
Don't leak the AVIOContext
Diffstat (limited to 'examples')
-rw-r--r-- | examples/alffplay.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
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<AVIOContext,AVIOContextDeleter>; + 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 "<<mFilename <<std::endl; return false; } + mIOContext.reset(avioctx); /* Open movie file. If avformat_open_input fails it will automatically free * this context, so don't set it onto a smart pointer yet. */ AVFormatContext *fmtctx = avformat_alloc_context(); - fmtctx->pb = avioctx; + fmtctx->pb = mIOContext.get(); fmtctx->interrupt_callback = intcb; if(avformat_open_input(&fmtctx, mFilename.c_str(), nullptr, nullptr) != 0) { |