From 276838044608a4707aa6e886e73f804ee41096f7 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 11 Oct 2020 18:57:37 +0200 Subject: [PATCH] Fixed several errors reported by Valgrind. --- INSTALL.md | 10 +++++++++- es-app/src/CollectionSystemManager.cpp | 7 +++++++ es-app/src/guis/GuiMetaDataEd.cpp | 3 ++- es-app/src/main.cpp | 2 +- es-core/src/components/SwitchComponent.cpp | 1 + es-core/src/components/VideoComponent.cpp | 1 + es-core/src/components/VideoComponent.h | 2 +- es-core/src/components/VideoVlcComponent.cpp | 5 ++--- 8 files changed, 24 insertions(+), 7 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 10c85dda2..14b5b10ea 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -65,7 +65,15 @@ You can then profile the code with valgrind: valgrind --tool=callgrind ./emulationstation ``` -The output file from valgrind can be loaded into a tool such as KCachegrind for data analysis. +The output file can be loaded into a tool such as KCachegrind for data analysis. + +To check for memory leaks, the following command is useful: + +``` +valgrind --tool=memcheck --leak-check=full ./emulationstation +``` + +Note that you can also profile either a normal build or a debug build, but it's recommended to use the profiling build for reasons that is beyond the scope of this document. To build ES with CEC support, add the corresponding option, for example: diff --git a/es-app/src/CollectionSystemManager.cpp b/es-app/src/CollectionSystemManager.cpp index 34f4c668f..49d9295e0 100644 --- a/es-app/src/CollectionSystemManager.cpp +++ b/es-app/src/CollectionSystemManager.cpp @@ -98,6 +98,13 @@ CollectionSystemManager::~CollectionSystemManager() saveCustomCollection(it->second.system); delete it->second.system; } + + // Delete the auto collections systems. + for (auto it = mAutoCollectionSystemsData.cbegin(); + it != mAutoCollectionSystemsData.cend(); it++) { + delete (*it).second.system; + } + sInstance = nullptr; } diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index 9fd0c34ac..ee39ee6b8 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -49,7 +49,8 @@ GuiMetaDataEd::GuiMetaDataEd( mMetaData(md), mSavedCallback(saveCallback), mClearGameFunc(clearGameFunc), - mDeleteGameFunc(deleteGameFunc) + mDeleteGameFunc(deleteGameFunc), + mMediaFilesUpdated(false) { addChild(&mBackground); addChild(&mGrid); diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 5626406de..9c6ad4247 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -466,7 +466,7 @@ int main(int argc, char* argv[]) bool splashScreen = Settings::getInstance()->getBool("SplashScreen"); bool splashScreenProgress = Settings::getInstance()->getBool("SplashScreenProgress"); - SDL_Event event; + SDL_Event event {}; if (!window.init()) { LOG(LogError) << "Window failed to initialize."; diff --git a/es-core/src/components/SwitchComponent.cpp b/es-core/src/components/SwitchComponent.cpp index 6565234e5..8b313223c 100644 --- a/es-core/src/components/SwitchComponent.cpp +++ b/es-core/src/components/SwitchComponent.cpp @@ -16,6 +16,7 @@ SwitchComponent::SwitchComponent( : GuiComponent(window), mImage(window), mState(state), + mOriginalValue(state), mColorOriginalValue(DEFAULT_COLORSHIFT), mColorChangedValue(DEFAULT_COLORSHIFT) { diff --git a/es-core/src/components/VideoComponent.cpp b/es-core/src/components/VideoComponent.cpp index abde15809..af229132d 100644 --- a/es-core/src/components/VideoComponent.cpp +++ b/es-core/src/components/VideoComponent.cpp @@ -74,6 +74,7 @@ VideoComponent::VideoComponent( mGameLaunched(false), mBlockPlayer(false), mTargetIsMax(false), + mFadeIn(1.0), mTargetSize(0, 0) { // Setup the default configuration. diff --git a/es-core/src/components/VideoComponent.h b/es-core/src/components/VideoComponent.h index 3f7e2d90b..37b06d70f 100644 --- a/es-core/src/components/VideoComponent.h +++ b/es-core/src/components/VideoComponent.h @@ -108,7 +108,6 @@ protected: unsigned mVideoHeight; Vector2f mTargetSize; std::shared_ptr mTexture; - float mFadeIn; // Used for fading in the video screensaver. std::string mStaticImagePath; ImageComponent mStaticImage; @@ -125,6 +124,7 @@ protected: bool mGameLaunched; bool mBlockPlayer; bool mTargetIsMax; + float mFadeIn; // Used for fading in the video screensaver. Configuration mConfig; }; diff --git a/es-core/src/components/VideoVlcComponent.cpp b/es-core/src/components/VideoVlcComponent.cpp index 9c8f396a2..47427b238 100644 --- a/es-core/src/components/VideoVlcComponent.cpp +++ b/es-core/src/components/VideoVlcComponent.cpp @@ -51,10 +51,8 @@ static void display(void* /*data*/, void* /*id*/) { } VideoVlcComponent::VideoVlcComponent(Window* window, std::string subtitles) - : VideoComponent(window), mMediaPlayer(nullptr) + : VideoComponent(window), mMediaPlayer(nullptr), mContext({}) { - memset(&mContext, 0, sizeof(mContext)); - // Get an empty texture for rendering the video. mTexture = TextureResource::get(""); @@ -65,6 +63,7 @@ VideoVlcComponent::VideoVlcComponent(Window* window, std::string subtitles) VideoVlcComponent::~VideoVlcComponent() { stopVideo(); + mTexture.reset(); } void VideoVlcComponent::setResize(float width, float height)