From 54d32817d5dd49effb2ce71e0ca76f939729e128 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Wed, 19 May 2021 17:12:41 +0200 Subject: [PATCH] Use av_free and maybe get Coverity to understand --- extern/osg-ffmpeg-videoplayer/videostate.cpp | 21 ++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/extern/osg-ffmpeg-videoplayer/videostate.cpp b/extern/osg-ffmpeg-videoplayer/videostate.cpp index 1c2fcee4e2..c3cb412e9a 100644 --- a/extern/osg-ffmpeg-videoplayer/videostate.cpp +++ b/extern/osg-ffmpeg-videoplayer/videostate.cpp @@ -62,6 +62,15 @@ namespace av_frame_free(&frame); } }; + + template + struct AVFree + { + void operator()(T* frame) const + { + av_free(&frame); + } + }; } namespace Video @@ -105,7 +114,7 @@ void VideoState::setAudioFactory(MovieAudioFactory *factory) void PacketQueue::put(AVPacket *pkt) { - std::unique_ptr pkt1(static_cast(av_malloc(sizeof(AVPacketList)))); + std::unique_ptr> pkt1(static_cast(av_malloc(sizeof(AVPacketList)))); if(!pkt1) throw std::bad_alloc(); if(pkt == &flush_pkt) @@ -116,14 +125,14 @@ void PacketQueue::put(AVPacket *pkt) pkt1->next = nullptr; std::lock_guard lock(this->mutex); - + AVPacketList* ptr = pkt1.release(); if(!last_pkt) - this->first_pkt = pkt1.get(); + this->first_pkt = ptr; else - this->last_pkt->next = pkt1.get(); - this->last_pkt = pkt1.release(); + this->last_pkt->next = ptr; + this->last_pkt = ptr; this->nb_packets++; - this->size += this->last_pkt->pkt.size; + this->size += ptr->pkt.size; this->cond.notify_one(); }