Fixed several errors reported by Valgrind.

This commit is contained in:
Leon Styhre 2020-10-11 18:57:37 +02:00
parent c2b3b029e5
commit 2768380446
8 changed files with 24 additions and 7 deletions

View file

@ -65,7 +65,15 @@ You can then profile the code with valgrind:
valgrind --tool=callgrind ./emulationstation 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: To build ES with CEC support, add the corresponding option, for example:

View file

@ -98,6 +98,13 @@ CollectionSystemManager::~CollectionSystemManager()
saveCustomCollection(it->second.system); saveCustomCollection(it->second.system);
delete 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; sInstance = nullptr;
} }

View file

@ -49,7 +49,8 @@ GuiMetaDataEd::GuiMetaDataEd(
mMetaData(md), mMetaData(md),
mSavedCallback(saveCallback), mSavedCallback(saveCallback),
mClearGameFunc(clearGameFunc), mClearGameFunc(clearGameFunc),
mDeleteGameFunc(deleteGameFunc) mDeleteGameFunc(deleteGameFunc),
mMediaFilesUpdated(false)
{ {
addChild(&mBackground); addChild(&mBackground);
addChild(&mGrid); addChild(&mGrid);

View file

@ -466,7 +466,7 @@ int main(int argc, char* argv[])
bool splashScreen = Settings::getInstance()->getBool("SplashScreen"); bool splashScreen = Settings::getInstance()->getBool("SplashScreen");
bool splashScreenProgress = Settings::getInstance()->getBool("SplashScreenProgress"); bool splashScreenProgress = Settings::getInstance()->getBool("SplashScreenProgress");
SDL_Event event; SDL_Event event {};
if (!window.init()) { if (!window.init()) {
LOG(LogError) << "Window failed to initialize."; LOG(LogError) << "Window failed to initialize.";

View file

@ -16,6 +16,7 @@ SwitchComponent::SwitchComponent(
: GuiComponent(window), : GuiComponent(window),
mImage(window), mImage(window),
mState(state), mState(state),
mOriginalValue(state),
mColorOriginalValue(DEFAULT_COLORSHIFT), mColorOriginalValue(DEFAULT_COLORSHIFT),
mColorChangedValue(DEFAULT_COLORSHIFT) mColorChangedValue(DEFAULT_COLORSHIFT)
{ {

View file

@ -74,6 +74,7 @@ VideoComponent::VideoComponent(
mGameLaunched(false), mGameLaunched(false),
mBlockPlayer(false), mBlockPlayer(false),
mTargetIsMax(false), mTargetIsMax(false),
mFadeIn(1.0),
mTargetSize(0, 0) mTargetSize(0, 0)
{ {
// Setup the default configuration. // Setup the default configuration.

View file

@ -108,7 +108,6 @@ protected:
unsigned mVideoHeight; unsigned mVideoHeight;
Vector2f mTargetSize; Vector2f mTargetSize;
std::shared_ptr<TextureResource> mTexture; std::shared_ptr<TextureResource> mTexture;
float mFadeIn; // Used for fading in the video screensaver.
std::string mStaticImagePath; std::string mStaticImagePath;
ImageComponent mStaticImage; ImageComponent mStaticImage;
@ -125,6 +124,7 @@ protected:
bool mGameLaunched; bool mGameLaunched;
bool mBlockPlayer; bool mBlockPlayer;
bool mTargetIsMax; bool mTargetIsMax;
float mFadeIn; // Used for fading in the video screensaver.
Configuration mConfig; Configuration mConfig;
}; };

View file

@ -51,10 +51,8 @@ static void display(void* /*data*/, void* /*id*/) {
} }
VideoVlcComponent::VideoVlcComponent(Window* window, std::string subtitles) 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. // Get an empty texture for rendering the video.
mTexture = TextureResource::get(""); mTexture = TextureResource::get("");
@ -65,6 +63,7 @@ VideoVlcComponent::VideoVlcComponent(Window* window, std::string subtitles)
VideoVlcComponent::~VideoVlcComponent() VideoVlcComponent::~VideoVlcComponent()
{ {
stopVideo(); stopVideo();
mTexture.reset();
} }
void VideoVlcComponent::setResize(float width, float height) void VideoVlcComponent::setResize(float width, float height)