~aleteoryx/muditaos

a8fd5d25ec9589660fcbd316d2dcf13f74542a09 — Adam Wulkiewicz 3 years ago 255d03a
[MOS-691] Fix memory leaks in APN settings

Replace objects created on heap with class members.
M module-apps/application-settings/windows/network/ApnOptionsWindow.cpp => module-apps/application-settings/windows/network/ApnOptionsWindow.cpp +5 -5
@@ 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<gui::Option>


@@ 34,7 34,7 @@ namespace gui
        optionsList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            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<gui::option::OptionSettings>(
            utils::translate("app_settings_apn_options_set_as_default"),
            [=](gui::Item &item) {
                apnSettingsModel->setAsDefaultAPN(apn);
                apnSettingsModel.setAsDefaultAPN(apn);
                application->returnToPreviousWindow();
                return true;
            },

M module-apps/application-settings/windows/network/ApnOptionsWindow.hpp => module-apps/application-settings/windows/network/ApnOptionsWindow.hpp +2 -2
@@ 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<gui::Option> override;
        auto handleSwitchData(SwitchData *data) -> bool override;
        std::shared_ptr<packet_data::APN::Config> apn;
        ApnSettingsModel *apnSettingsModel = nullptr;
        ApnSettingsModel apnSettingsModel;
    };
} // namespace gui

M module-apps/application-settings/windows/network/NewApnWindow.cpp => module-apps/application-settings/windows/network/NewApnWindow.cpp +4 -4
@@ 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<packet_data::APN::Config>()), newApnModel{std::make_shared<NewApnModel>(app)}
          apn(std::make_shared<packet_data::APN::Config>()), newApnModel{std::make_shared<NewApnModel>(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();
            }

M module-apps/application-settings/windows/network/NewApnWindow.hpp => module-apps/application-settings/windows/network/NewApnWindow.hpp +2 -2
@@ 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<packet_data::APN::Config> apn;
        std::shared_ptr<NewApnModel> newApnModel;
        ApnSettingsModel *apnSettingsModel = nullptr;
        ApnSettingsModel apnSettingsModel;
        gui::ListView *list                = nullptr;
    };


M pure_changelog.md => pure_changelog.md +1 -0
@@ 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]