From a8fd5d25ec9589660fcbd316d2dcf13f74542a09 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Mon, 5 Sep 2022 18:37:15 +0200 Subject: [PATCH] [MOS-691] Fix memory leaks in APN settings Replace objects created on heap with class members. --- .../windows/network/ApnOptionsWindow.cpp | 10 +++++----- .../windows/network/ApnOptionsWindow.hpp | 4 ++-- .../windows/network/NewApnWindow.cpp | 8 ++++---- .../windows/network/NewApnWindow.hpp | 4 ++-- pure_changelog.md | 1 + 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/module-apps/application-settings/windows/network/ApnOptionsWindow.cpp b/module-apps/application-settings/windows/network/ApnOptionsWindow.cpp index e66b28d78f0b78cea05fd368c3c141aa40d8b4cc..549507d213c918db26268f4389b8165e47fb1fff 100644 --- a/module-apps/application-settings/windows/network/ApnOptionsWindow.cpp +++ b/module-apps/application-settings/windows/network/ApnOptionsWindow.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "ApnOptionsWindow.hpp" @@ -10,10 +10,10 @@ namespace gui { - ApnOptionsWindow::ApnOptionsWindow(app::ApplicationCommon *app) : BaseSettingsWindow(app, window::name::apn_options) + ApnOptionsWindow::ApnOptionsWindow(app::ApplicationCommon *app) + : BaseSettingsWindow(app, window::name::apn_options), apnSettingsModel(app) { setTitle(utils::translate("common_options_title")); - apnSettingsModel = new ApnSettingsModel(application); } auto ApnOptionsWindow::buildOptionsList() -> std::list @@ -34,7 +34,7 @@ namespace gui optionsList.emplace_back(std::make_unique( utils::translate("app_settings_apn_options_delete"), [=](gui::Item &item) { - apnSettingsModel->removeAPN(apn); + apnSettingsModel.removeAPN(apn); application->returnToPreviousWindow(); return true; }, @@ -44,7 +44,7 @@ namespace gui optionsList.emplace_back(std::make_unique( utils::translate("app_settings_apn_options_set_as_default"), [=](gui::Item &item) { - apnSettingsModel->setAsDefaultAPN(apn); + apnSettingsModel.setAsDefaultAPN(apn); application->returnToPreviousWindow(); return true; }, diff --git a/module-apps/application-settings/windows/network/ApnOptionsWindow.hpp b/module-apps/application-settings/windows/network/ApnOptionsWindow.hpp index 644462c46ed6b8cf99b5add8a212a98e401d9331..211c010d7a565d555956de688286aad0271a1621 100644 --- a/module-apps/application-settings/windows/network/ApnOptionsWindow.hpp +++ b/module-apps/application-settings/windows/network/ApnOptionsWindow.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -18,6 +18,6 @@ namespace gui auto buildOptionsList() -> std::list override; auto handleSwitchData(SwitchData *data) -> bool override; std::shared_ptr apn; - ApnSettingsModel *apnSettingsModel = nullptr; + ApnSettingsModel apnSettingsModel; }; } // namespace gui diff --git a/module-apps/application-settings/windows/network/NewApnWindow.cpp b/module-apps/application-settings/windows/network/NewApnWindow.cpp index 8eeb38a838de35b21c774f63a0ea0cf576792e63..6f085196dc0796c80595c9ab38509eec7e31e0fd 100644 --- a/module-apps/application-settings/windows/network/NewApnWindow.cpp +++ b/module-apps/application-settings/windows/network/NewApnWindow.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "NewApnWindow.hpp" @@ -11,7 +11,8 @@ namespace gui NewApnWindow::NewApnWindow(app::ApplicationCommon *app) : AppWindow(app, gui::window::name::new_apn), - apn(std::make_shared()), newApnModel{std::make_shared(app)} + apn(std::make_shared()), newApnModel{std::make_shared(app)}, + apnSettingsModel(app) { buildInterface(); } @@ -38,7 +39,6 @@ namespace gui style::settings::window::newApn::h, newApnModel); setFocusItem(list); - apnSettingsModel = new ApnSettingsModel(application); } void NewApnWindow::destroyInterface() @@ -100,7 +100,7 @@ namespace gui newApnModel->saveData(apn); LOG_DEBUG("APN: \"%s\" ", apn->apn.c_str()); if (apn != nullptr && !apn->apn.empty()) { - apnSettingsModel->saveAPN(apn); + apnSettingsModel.saveAPN(apn); LOG_INFO("APN record saved: \"%s\" ", apn->apn.c_str()); application->returnToPreviousWindow(); } diff --git a/module-apps/application-settings/windows/network/NewApnWindow.hpp b/module-apps/application-settings/windows/network/NewApnWindow.hpp index 83644d52e32d0205511c8dfc669b4ba6611eaf08..aaceafe3a3f22501e67ba587537b726aff06f280 100644 --- a/module-apps/application-settings/windows/network/NewApnWindow.hpp +++ b/module-apps/application-settings/windows/network/NewApnWindow.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -27,7 +27,7 @@ namespace gui void setSaveButtonVisible(bool visible); std::shared_ptr apn; std::shared_ptr newApnModel; - ApnSettingsModel *apnSettingsModel = nullptr; + ApnSettingsModel apnSettingsModel; gui::ListView *list = nullptr; }; diff --git a/pure_changelog.md b/pure_changelog.md index 91f1c37dea9efc8b5d672ac1e01cc445f1eb53ed..3b8d1e87637aa12c5b6193e511fbe766fdddc114 100644 --- a/pure_changelog.md +++ b/pure_changelog.md @@ -21,6 +21,7 @@ * Fixed turning on loudspeaker before outgoing call is answered * Fixed PLAY label translation in German * Fixed USB connection/disconnection detection +* Fixed memory leaks in APN settings * Added basic MMS handling ## [1.3.0 2022-08-04]