Commit 5daaa842 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii Committed by Aleix Pol Gonzalez
Browse files

Fix a crash in flatpak update notifier

Currently, the update notifier will crash due to a segmentation fault if
a flatpak package has been updated.

The segmentation fault occurs because the installationChanged() callback
expects the user data to have a type of FlatpakNotifier, but in reality
it's FlatpakNotifier::Installation.

In order to fix the crash, this patch makes the installationChanged()
callback cast user data to correct type.
parent c0372aec
...@@ -35,19 +35,18 @@ static void installationChanged(GFileMonitor *monitor, GFile *child, GFile *othe ...@@ -35,19 +35,18 @@ static void installationChanged(GFileMonitor *monitor, GFile *child, GFile *othe
Q_UNUSED(other_file); Q_UNUSED(other_file);
Q_UNUSED(event_type); Q_UNUSED(event_type);
FlatpakNotifier *notifier = (FlatpakNotifier*) self; FlatpakNotifier::Installation *installation = (FlatpakNotifier::Installation*) self;
if (!notifier) { if (!installation)
return; return;
}
if (notifier->m_user.m_monitor == monitor) FlatpakNotifier *notifier = installation->m_notifier;
notifier->loadRemoteUpdates(&notifier->m_user); notifier->loadRemoteUpdates(installation);
else
notifier->loadRemoteUpdates(&notifier->m_system);
} }
FlatpakNotifier::FlatpakNotifier(QObject* parent) FlatpakNotifier::FlatpakNotifier(QObject* parent)
: BackendNotifierModule(parent) : BackendNotifierModule(parent)
, m_user(this)
, m_system(this)
, m_cancellable(g_cancellable_new()) , m_cancellable(g_cancellable_new())
{ {
QTimer *dailyCheck = new QTimer(this); QTimer *dailyCheck = new QTimer(this);
...@@ -55,6 +54,11 @@ FlatpakNotifier::FlatpakNotifier(QObject* parent) ...@@ -55,6 +54,11 @@ FlatpakNotifier::FlatpakNotifier(QObject* parent)
connect(dailyCheck, &QTimer::timeout, this, &FlatpakNotifier::recheckSystemUpdateNeeded); connect(dailyCheck, &QTimer::timeout, this, &FlatpakNotifier::recheckSystemUpdateNeeded);
} }
FlatpakNotifier::Installation::Installation(FlatpakNotifier *notifier)
: m_notifier(notifier)
{
}
FlatpakNotifier::Installation::~Installation() FlatpakNotifier::Installation::~Installation()
{ {
if (m_monitor) if (m_monitor)
......
...@@ -43,10 +43,12 @@ public: ...@@ -43,10 +43,12 @@ public:
bool needsReboot() const override { return false; } bool needsReboot() const override { return false; }
struct Installation { struct Installation {
explicit Installation(FlatpakNotifier *notifier);
~Installation(); ~Installation();
bool ensureInitialized(std::function<FlatpakInstallation*()> func, GCancellable *, GError **error); bool ensureInitialized(std::function<FlatpakInstallation*()> func, GCancellable *, GError **error);
FlatpakNotifier *m_notifier;
bool m_hasUpdates = false; bool m_hasUpdates = false;
GFileMonitor *m_monitor = nullptr; GFileMonitor *m_monitor = nullptr;
FlatpakInstallation *m_installation = nullptr; FlatpakInstallation *m_installation = nullptr;
......
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