DolphinQt/InputCommon: Fix a few memory leaks.

This commit is contained in:
Jordan Woyak 2019-03-17 12:51:50 -05:00
parent 54e09886d8
commit 725d34b2f0
10 changed files with 31 additions and 12 deletions

View File

@ -63,7 +63,7 @@ GameConfigEdit::GameConfigEdit(QWidget* parent, const QString& path, bool read_o
m_completer = new QCompleter(m_edit);
auto* completion_model = new QStringListModel;
auto* completion_model = new QStringListModel(m_completer);
completion_model->setStringList(m_completions);
m_completer->setModel(completion_model);
@ -77,8 +77,6 @@ GameConfigEdit::GameConfigEdit(QWidget* parent, const QString& path, bool read_o
void GameConfigEdit::CreateWidgets()
{
m_menu = new QMenu;
m_edit = new QTextEdit;
m_edit->setReadOnly(m_read_only);
m_edit->setAcceptRichText(false);
@ -89,6 +87,8 @@ void GameConfigEdit::CreateWidgets()
menu_button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
menu_button->setText(tr("Presets"));
m_menu = new QMenu(menu_button);
menu_button->setMenu(m_menu);
layout->addWidget(menu_button);

View File

@ -104,7 +104,7 @@ QGroupBox* InfoWidget::CreateBannerDetails()
m_name = CreateValueDisplay();
m_maker = CreateValueDisplay();
m_description = new QTextEdit();
m_description = new QTextEdit(group);
m_description->setReadOnly(true);
CreateLanguageSelector();
@ -153,7 +153,7 @@ void InfoWidget::SaveBanner()
QLineEdit* InfoWidget::CreateValueDisplay(const QString& value)
{
QLineEdit* value_display = new QLineEdit(value);
QLineEdit* value_display = new QLineEdit(value, this);
value_display->setReadOnly(true);
value_display->setCursorPosition(0);
return value_display;

View File

@ -196,7 +196,7 @@ void GameList::MakeEmptyView()
"Double-click here to set a games directory..."));
m_empty->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
auto event_filter = new DoubleClickEventFilter{};
auto event_filter = new DoubleClickEventFilter{m_empty};
m_empty->installEventFilter(event_filter);
connect(event_filter, &DoubleClickEventFilter::doubleClicked, [this] {
auto current_dir = QDir::currentPath();

View File

@ -323,7 +323,7 @@ void MainWindow::InitCoreCallbacks()
static void InstallHotkeyFilter(QWidget* dialog)
{
auto* filter = new WindowActivationEventFilter();
auto* filter = new WindowActivationEventFilter(dialog);
dialog->installEventFilter(filter);
filter->connect(filter, &WindowActivationEventFilter::windowDeactivated,

View File

@ -271,7 +271,7 @@ void MenuBar::AddToolsMenu()
m_perform_online_update_menu->addAction(tr("United States"), this,
[this] { emit PerformOnlineUpdate("USA"); });
QMenu* menu = new QMenu(tr("Connect Wii Remotes"));
QMenu* menu = new QMenu(tr("Connect Wii Remotes"), tools_menu);
tools_menu->addSeparator();
tools_menu->addMenu(menu);

View File

@ -6,6 +6,10 @@
#include "DolphinQt/QtUtils/DoubleClickEventFilter.h"
DoubleClickEventFilter::DoubleClickEventFilter(QObject* parent) : QObject(parent)
{
}
bool DoubleClickEventFilter::eventFilter(QObject* object, QEvent* event)
{
if (event->type() == QEvent::MouseButtonDblClick)

View File

@ -9,6 +9,9 @@
class DoubleClickEventFilter : public QObject
{
Q_OBJECT
public:
explicit DoubleClickEventFilter(QObject* parent);
signals:
void doubleClicked();

View File

@ -7,6 +7,10 @@
#include "DolphinQt/QtUtils/WindowActivationEventFilter.h"
WindowActivationEventFilter::WindowActivationEventFilter(QObject* parent) : QObject(parent)
{
}
bool WindowActivationEventFilter::eventFilter(QObject* object, QEvent* event)
{
if (event->type() == QEvent::WindowDeactivate)

View File

@ -9,6 +9,9 @@
class WindowActivationEventFilter : public QObject
{
Q_OBJECT
public:
explicit WindowActivationEventFilter(QObject* parent);
signals:
void windowActivated();
void windowDeactivated();

View File

@ -16,6 +16,7 @@
#include "Common/Flag.h"
#include "Common/Logging/Log.h"
#include "Common/MathUtil.h"
#include "Common/ScopeGuard.h"
#include "Common/StringUtil.h"
#include "Common/Thread.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
@ -40,10 +41,14 @@ static void HotplugThreadFunc()
NOTICE_LOG(SERIALINTERFACE, "evdev hotplug thread started");
udev* const udev = udev_new();
Common::ScopeGuard udev_guard([udev] { udev_unref(udev); });
ASSERT_MSG(PAD, udev != nullptr, "Couldn't initialize libudev.");
// Set up monitoring
udev_monitor* const monitor = udev_monitor_new_from_netlink(udev, "udev");
Common::ScopeGuard monitor_guard([monitor] { udev_monitor_unref(monitor); });
udev_monitor_filter_add_match_subsystem_devtype(monitor, "input", nullptr);
udev_monitor_enable_receiving(monitor);
const int monitor_fd = udev_monitor_get_fd(monitor);
@ -61,11 +66,11 @@ static void HotplugThreadFunc()
if (ret < 1 || !FD_ISSET(monitor_fd, &fds))
continue;
std::unique_ptr<udev_device, decltype(&udev_device_unref)> dev{
udev_monitor_receive_device(monitor), udev_device_unref};
udev_device* const dev = udev_monitor_receive_device(monitor);
Common::ScopeGuard dev_guard([dev] { udev_device_unref(dev); });
const char* const action = udev_device_get_action(dev.get());
const char* const devnode = udev_device_get_devnode(dev.get());
const char* const action = udev_device_get_action(dev);
const char* const devnode = udev_device_get_devnode(dev);
if (!devnode)
continue;