From 28c66225c9cd04a515e20da2fd483329eba6cc6e Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 22 Mar 2021 18:12:25 +0100 Subject: [PATCH] Fixed two memory leaks in VideoVlcComponent. --- es-core/src/Window.cpp | 2 ++ es-core/src/components/VideoVlcComponent.cpp | 13 +++++++++++++ es-core/src/components/VideoVlcComponent.h | 2 ++ 3 files changed, 17 insertions(+) diff --git a/es-core/src/Window.cpp b/es-core/src/Window.cpp index 6d1e81966..d01eaac7c 100644 --- a/es-core/src/Window.cpp +++ b/es-core/src/Window.cpp @@ -11,6 +11,7 @@ #include "components/HelpComponent.h" #include "components/ImageComponent.h" +#include "components/VideoVlcComponent.h" #include "resources/Font.h" #include "Sound.h" #include "InputManager.h" @@ -131,6 +132,7 @@ void Window::deinit() InputManager::getInstance()->deinit(); ResourceManager::getInstance()->unloadAll(); + VideoVlcComponent::deinit(); Renderer::deinit(); } diff --git a/es-core/src/components/VideoVlcComponent.cpp b/es-core/src/components/VideoVlcComponent.cpp index 0cf8b6c07..5df98bc53 100644 --- a/es-core/src/components/VideoVlcComponent.cpp +++ b/es-core/src/components/VideoVlcComponent.cpp @@ -34,6 +34,7 @@ VideoVlcComponent::VideoVlcComponent( Window* window) : VideoComponent(window), mMediaPlayer(nullptr), + mMedia(nullptr), mContext({}), mHasSetAudioVolume(false) { @@ -50,6 +51,14 @@ VideoVlcComponent::~VideoVlcComponent() mTexture.reset(); } +void VideoVlcComponent::deinit() +{ + if (mVLC) { + libvlc_release(mVLC); + mVLC = nullptr; + } +} + void VideoVlcComponent::setResize(float width, float height) { // This resize function is used when stretching videos to full screen in the video screensaver. @@ -358,6 +367,9 @@ void VideoVlcComponent::startVideo() } } libvlc_media_tracks_release(tracks, track_count); + libvlc_media_parse_stop(mMedia); + libvlc_event_detach(libvlc_media_event_manager(mMedia), + libvlc_MediaParsedChanged, VlcMediaParseCallback, 0); // Make sure we found a valid video track. if ((mVideoWidth > 0) && (mVideoHeight > 0)) { @@ -466,6 +478,7 @@ void VideoVlcComponent::stopVideo() libvlc_media_player_release(mMediaPlayer); libvlc_media_release(mMedia); mMediaPlayer = nullptr; + mMedia = nullptr; freeContext(); } } diff --git a/es-core/src/components/VideoVlcComponent.h b/es-core/src/components/VideoVlcComponent.h index be452c7b7..df5947810 100644 --- a/es-core/src/components/VideoVlcComponent.h +++ b/es-core/src/components/VideoVlcComponent.h @@ -31,6 +31,8 @@ public: VideoVlcComponent(Window* window); virtual ~VideoVlcComponent(); + static void deinit(); + // Resize the video to fit this size. If one axis is zero, scale that axis to maintain // aspect ratio. If both are non-zero, potentially break the aspect ratio. If both are // zero, no resizing. This can be set before or after a video is loaded.