From aad7f648005bed47fcc151927f6af22e077d9b62 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sun, 26 Jul 2020 18:32:53 +0200 Subject: [PATCH] configuration: Don't leak pointers and add messages to exceptions --- source/configuration.cpp | 10 +++++----- source/ui/ui.cpp | 8 +++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/source/configuration.cpp b/source/configuration.cpp index e62aefcf..7d19da77 100644 --- a/source/configuration.cpp +++ b/source/configuration.cpp @@ -44,18 +44,18 @@ streamfx::configuration::~configuration() streamfx::configuration::configuration() : _data(), _config_path() { { // Retrieve global configuration path. - const char* path = obs_module_config_path("config.json"); + char* path = obs_module_config_path("config.json"); _config_path = path; + bfree(path); } try { if (!std::filesystem::exists(_config_path) || !std::filesystem::is_regular_file(_config_path)) { - throw std::exception(); + throw std::runtime_error("Configuration does not exist."); } else { - obs_data_t* data = - obs_data_create_from_json_file_safe(_config_path.string().c_str(), path_backup_ext.data()); + obs_data_t* data = obs_data_create_from_json_file_safe(_config_path.string().c_str(), path_backup_ext.data()); if (!data) { - throw std::exception(); + throw std::runtime_error("Failed to load configuration from disk."); } else { _data = std::shared_ptr(data, obs::obs_data_deleter); } diff --git a/source/ui/ui.cpp b/source/ui/ui.cpp index 6e2e1f30..4cf2079a 100644 --- a/source/ui/ui.cpp +++ b/source/ui/ui.cpp @@ -59,13 +59,15 @@ inline void qt_cleanup_resource() bool streamfx::ui::handler::have_shown_about_streamfx(bool shown) { + auto config = streamfx::configuration::instance(); + auto data = config->get(); if (shown) { - obs_data_set_bool(streamfx::configuration::instance()->get().get(), _cfg_have_shown_about.data(), true); + obs_data_set_bool(data.get(), _cfg_have_shown_about.data(), true); } - if (streamfx::configuration::instance()->is_different_version()) { + if (config->is_different_version()) { return false; } else { - return obs_data_get_bool(streamfx::configuration::instance()->get().get(), _cfg_have_shown_about.data()); + return obs_data_get_bool(data.get(), _cfg_have_shown_about.data()); } }