From 1d04da620514689cd8f94cb34fd3649845a3032d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Tue, 26 Apr 2022 16:45:07 +0200 Subject: [PATCH] Make sure the ping timer exists to prevent crash if not available --- libnymea/network/ping.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libnymea/network/ping.cpp b/libnymea/network/ping.cpp index 0f1e7db3..a16202c7 100644 --- a/libnymea/network/ping.cpp +++ b/libnymea/network/ping.cpp @@ -49,6 +49,13 @@ NYMEA_LOGGING_CATEGORY(dcPingTraffic, "PingTraffic") Ping::Ping(QObject *parent) : QObject(parent) { + m_queueTimer = new QTimer(this); + m_queueTimer->setInterval(20); + m_queueTimer->setSingleShot(true); + connect(m_queueTimer, &QTimer::timeout, this, [=](){ + sendNextReply(); + }); + // Build socket descriptor m_socketDescriptor = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); if (m_socketDescriptor < 0) { @@ -78,13 +85,6 @@ Ping::Ping(QObject *parent) : QObject(parent) m_socketNotifier = new QSocketNotifier(m_socketDescriptor, QSocketNotifier::Read, this); connect(m_socketNotifier, &QSocketNotifier::activated, this, &Ping::onSocketReadyRead); - m_queueTimer = new QTimer(this); - m_queueTimer->setInterval(20); - m_queueTimer->setSingleShot(true); - connect(m_queueTimer, &QTimer::timeout, this, [=](){ - sendNextReply(); - }); - m_socketNotifier->setEnabled(true); m_available = true; qCDebug(dcPing()) << "ICMP socket set up successfully (Socket ID:" << m_socketDescriptor << ")";