From 0b6e479e0bafb2b1fdeb0832eb886cb78a8388b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Tue, 12 Jan 2021 12:59:04 +0100 Subject: [PATCH] Fix some Double Free and uninitialized Memory in Switch --- switch/include/discoverymanager.h | 2 +- switch/src/discoverymanager.cpp | 6 ------ switch/src/main.cpp | 7 +++++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/switch/include/discoverymanager.h b/switch/include/discoverymanager.h index 76c504d..49c8dcc 100644 --- a/switch/include/discoverymanager.h +++ b/switch/include/discoverymanager.h @@ -24,7 +24,7 @@ class DiscoveryManager struct sockaddr * host_addr = nullptr; size_t host_addr_len = 0; uint32_t GetIPv4BroadcastAddr(); - bool service_enable; + bool service_enable = false; public: typedef enum hoststate diff --git a/switch/src/discoverymanager.cpp b/switch/src/discoverymanager.cpp index e9abe5f..7fa7122 100644 --- a/switch/src/discoverymanager.cpp +++ b/switch/src/discoverymanager.cpp @@ -35,19 +35,13 @@ DiscoveryManager::~DiscoveryManager() { // join discovery thread if(this->service_enable) - { SetService(false); - } - - chiaki_discovery_fini(&this->discovery); } void DiscoveryManager::SetService(bool enable) { if(this->service_enable == enable) - { return; - } this->service_enable = enable; diff --git a/switch/src/main.cpp b/switch/src/main.cpp index 34e4b20..6b7c95e 100644 --- a/switch/src/main.cpp +++ b/switch/src/main.cpp @@ -129,8 +129,11 @@ int main(int argc, char *argv[]) // build sdl OpenGl and AV decoders graphical interface DiscoveryManager discoverymanager = DiscoveryManager(); - MainApplication app = MainApplication(&discoverymanager); - app.Load(); + { + // scope to delete MainApplication before SDL_Quit() + MainApplication app(&discoverymanager); + app.Load(); + } CHIAKI_LOGI(log, "Quit applet"); SDL_Quit();