fix a number of memory leaks

- some were with libav functions
- same were due to non-virtual destructors
This commit is contained in:
Chris Kirmse
2019-05-08 14:53:23 -07:00
parent 17a2258939
commit 833fcb8e8e
20 changed files with 63 additions and 30 deletions

View File

@@ -576,6 +576,12 @@ void FFmpegReader::Close() {
ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::Close", "", -1, "", -1, "", -1, "", -1, "", -1, "", -1);
if (packet) {
// Remove previous packet before getting next one
RemoveAVPacket(packet);
packet = NULL;
}
// Close the codec
if (info.has_video) {
avcodec_flush_buffers(pCodecCtx);
@@ -624,6 +630,8 @@ void FFmpegReader::Close() {
seek_video_frame_found = 0;
current_video_frame = 0;
has_missing_frames = false;
last_video_frame.reset();
}
}
@@ -926,7 +934,9 @@ std::shared_ptr<Frame> FFmpegReader::ReadStream(int64_t requested_frame) {
// down processing considerably, but might be more stable on some systems.
#pragma omp taskwait
}
}
} else {
RemoveAVFrame(pFrame);
}
}
// Audio packet
@@ -1063,7 +1073,7 @@ bool FFmpegReader::GetAVFrame() {
{
next_frame2 = next_frame;
}
pFrame = new AVFrame();
pFrame = AV_ALLOCATE_FRAME();
while (ret >= 0) {
ret = avcodec_receive_frame(pCodecCtx, next_frame2);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
@@ -1206,6 +1216,7 @@ void FFmpegReader::ProcessVideoPacket(int64_t requested_frame) {
int width = info.width;
int64_t video_length = info.video_length;
AVFrame *my_frame = pFrame;
pFrame = NULL;
// Add video frame to list of processing video frames
const GenericScopedLock <CriticalSection> lock(processingCriticalSection);