Commit 8c7079dd authored by Nikolai Kosjar's avatar Nikolai Kosjar Committed by Orgad Shaneh
Browse files

Beautifier: Fix leak of GeneralSettings

Direct leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x4f06b0 in operator new(unsigned long) (/home/nik/dev/creator/
ut/4.2_asan/bin/qtcreator+0x4f06b0)
    #1 0x7f4ac0e5d068 in
Beautifier::Internal::BeautifierPlugin::initialize(QStringList const&,
QString*) /home/nik/dev/creator/ut/4.2_asan/src/plugins/beautifier/
beautifierplugin.cpp:214:25
    #2 0x7f4ada1bb769 in
ExtensionSystem::Internal::PluginSpecPrivate::initializePlugin() /home/
nik/dev/creator/ut/4.2_asan/src/libs/extensionsystem/pluginspec.cpp:
1001:10
    #3 0x7f4ada1694b1 in
ExtensionSystem::Internal::PluginManagerPrivate::loadPlugin(ExtensionSystem::PluginSpec*,
ExtensionSystem::PluginSpec::State) /home/nik/dev/creator/ut/4.2_asan/
src/libs/extensionsystem/pluginmanager.cpp:1404:9
    #4

 0x7f4ada15b2b6 in
ExtensionSystem::Internal::PluginManagerPrivate::loadPlugins() /home/
nik/dev/creator/ut/4.2_asan/src/libs/extensionsystem/pluginmanager.cpp:
1239:9
    #5 0x7f4ada15ac6f in ExtensionSystem::PluginManager::loadPlugins() /
home/nik/dev/creator/ut/4.2_asan/src/libs/extensionsystem/
pluginmanager.cpp:362:12
    #6 0x50a97c in main /home/nik/dev/creator/ut/4.2_asan/src/app/
main.cpp:517:5
    #7 0x7f4ad65b282f in __libc_start_main /build/glibc-Qz8a69/
glibc-2.23/csu/../csu/libc-start.c:291

Change-Id: Iff1fd908d9a59b98e895599b1d73ca16536eee11
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent 659baae9
......@@ -215,7 +215,7 @@ void BeautifierPlugin::extensionsInitialized()
addAutoReleasedObject(object);
}
m_generalSettings = new GeneralSettings;
m_generalSettings.reset(new GeneralSettings);
auto settingsPage = new GeneralOptionsPage(m_generalSettings, toolIds, this);
addAutoReleasedObject(settingsPage);
......
......@@ -31,6 +31,7 @@
#include <QPlainTextEdit>
#include <QPointer>
#include <QSharedPointer>
namespace Core {
class IDocument;
......@@ -86,7 +87,7 @@ public:
private:
void updateActions(Core::IEditor *editor = nullptr);
QList<BeautifierAbstractTool *> m_tools;
GeneralSettings *m_generalSettings = nullptr;
QSharedPointer<GeneralSettings> m_generalSettings;
QHash<QObject*, QMetaObject::Connection> m_autoFormatConnections;
void formatEditor(TextEditor::TextEditorWidget *editor, const Command &command,
int startPos = -1, int endPos = 0);
......
......@@ -36,7 +36,7 @@
namespace Beautifier {
namespace Internal {
GeneralOptionsPageWidget::GeneralOptionsPageWidget(GeneralSettings *settings,
GeneralOptionsPageWidget::GeneralOptionsPageWidget(const QSharedPointer<GeneralSettings> &settings,
const QStringList &toolIds, QWidget *parent) :
QWidget(parent),
ui(new Ui::GeneralOptionsPage),
......@@ -73,8 +73,8 @@ void GeneralOptionsPageWidget::apply(bool *autoFormatChanged)
m_settings->save();
}
GeneralOptionsPage::GeneralOptionsPage(GeneralSettings *settings, const QStringList &toolIds,
QObject *parent) :
GeneralOptionsPage::GeneralOptionsPage(const QSharedPointer<GeneralSettings> &settings,
const QStringList &toolIds, QObject *parent) :
IOptionsPage(parent),
m_settings(settings),
m_toolIds(toolIds)
......
......@@ -28,6 +28,7 @@
#include <coreplugin/dialogs/ioptionspage.h>
#include <QPointer>
#include <QSharedPointer>
#include <QWidget>
namespace Beautifier {
......@@ -42,15 +43,15 @@ class GeneralOptionsPageWidget : public QWidget
Q_OBJECT
public:
explicit GeneralOptionsPageWidget(GeneralSettings *settings, const QStringList &toolIds,
QWidget *parent = nullptr);
explicit GeneralOptionsPageWidget(const QSharedPointer<GeneralSettings> &settings,
const QStringList &toolIds, QWidget *parent = nullptr);
virtual ~GeneralOptionsPageWidget();
void restore();
void apply(bool *autoFormatChanged);
private:
Ui::GeneralOptionsPage *ui;
GeneralSettings *m_settings;
QSharedPointer<GeneralSettings> m_settings;
};
class GeneralOptionsPage : public Core::IOptionsPage
......@@ -58,8 +59,8 @@ class GeneralOptionsPage : public Core::IOptionsPage
Q_OBJECT
public:
explicit GeneralOptionsPage(GeneralSettings *settings, const QStringList &toolIds,
QObject *parent = nullptr);
explicit GeneralOptionsPage(const QSharedPointer<GeneralSettings> &settings,
const QStringList &toolIds, QObject *parent = nullptr);
QWidget *widget() override;
void apply() override;
void finish() override;
......@@ -69,7 +70,7 @@ signals:
private:
QPointer<GeneralOptionsPageWidget> m_widget;
GeneralSettings *m_settings;
QSharedPointer<GeneralSettings> m_settings;
QStringList m_toolIds;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment