From 39de79d3cd678570f03c8d5d39b3a19d28158432 Mon Sep 17 00:00:00 2001 From: leetthewire Date: Fri, 25 Mar 2022 12:32:36 -0700 Subject: [PATCH] started to file updating for linux build --- client/client.pro | 8 ++ client/platforms/linux/leakdetector.cpp | 75 +++++++++++++++++++ client/platforms/linux/leakdetector.h | 41 ++++++++++ .../linuxsystemtraynotificationhandler.cpp | 2 +- client/ui/notificationhandler.cpp | 2 +- .../ui/pages_logic/ShareConnectionLogic.cpp | 4 + 6 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 client/platforms/linux/leakdetector.cpp create mode 100644 client/platforms/linux/leakdetector.h diff --git a/client/client.pro b/client/client.pro index d553b784..70550401 100644 --- a/client/client.pro +++ b/client/client.pro @@ -38,6 +38,7 @@ HEADERS += \ debug.h \ defines.h \ managementserver.h \ + platforms/linux/leakdetector.h \ protocols/protocols_defs.h \ settings.h \ ui/notificationhandler.h \ @@ -93,6 +94,7 @@ SOURCES += \ debug.cpp \ main.cpp \ managementserver.cpp \ + platforms/linux/leakdetector.cpp \ protocols/protocols_defs.cpp \ settings.cpp \ ui/notificationhandler.cpp \ @@ -191,6 +193,12 @@ macx { linux:!android { DEFINES += MVPN_LINUX +HEADERS += \ + platforms/linux/linuxsystemtraynotificationhandler.h \ + +SOURCES += \ + platforms/linux/linuxsystemtraynotificationhandler.cpp \ + LIBS += /usr/lib/x86_64-linux-gnu/libcrypto.a LIBS += /usr/lib/x86_64-linux-gnu/libssl.a diff --git a/client/platforms/linux/leakdetector.cpp b/client/platforms/linux/leakdetector.cpp new file mode 100644 index 00000000..7a092a8a --- /dev/null +++ b/client/platforms/linux/leakdetector.cpp @@ -0,0 +1,75 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "leakdetector.h" + +#include +#include +#include +#include + +#ifdef MVPN_DEBUG +static QMutex s_leakDetector; + +QHash> s_leaks; +#endif + +LeakDetector::LeakDetector() { +#ifndef MVPN_DEBUG + qFatal("LeakDetector _must_ be created in debug builds only!"); +#endif +} + +LeakDetector::~LeakDetector() { +#ifdef MVPN_DEBUG + QTextStream out(stderr); + + out << "== Mozilla VPN - Leak report ===================" << Qt::endl; + + bool hasLeaks = false; + for (auto i = s_leaks.begin(); i != s_leaks.end(); ++i) { + QString className = i.key(); + + if (i->size() == 0) { + continue; + } + + hasLeaks = true; + out << className << Qt::endl; + + for (auto l = i->begin(); l != i->end(); ++l) { + out << " - ptr: " << l.key() << " size:" << l.value() << Qt::endl; + } + } + + if (!hasLeaks) { + out << "No leaks detected." << Qt::endl; + } +#endif +} + +#ifdef MVPN_DEBUG +void LeakDetector::logCtor(void* ptr, const char* typeName, uint32_t size) { + QMutexLocker lock(&s_leakDetector); + + QString type(typeName); + if (!s_leaks.contains(type)) { + s_leaks.insert(type, QHash()); + } + + s_leaks[type].insert(ptr, size); +} + +void LeakDetector::logDtor(void* ptr, const char* typeName, uint32_t size) { + QMutexLocker lock(&s_leakDetector); + + QString type(typeName); + Q_ASSERT(s_leaks.contains(type)); + + QHash& leak = s_leaks[type]; + Q_ASSERT(leak.contains(ptr)); + Q_ASSERT(leak[ptr] == size); + leak.remove(ptr); +} +#endif diff --git a/client/platforms/linux/leakdetector.h b/client/platforms/linux/leakdetector.h new file mode 100644 index 00000000..3016137c --- /dev/null +++ b/client/platforms/linux/leakdetector.h @@ -0,0 +1,41 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef LEAKDETECTOR_H +#define LEAKDETECTOR_H + +#include + +#ifdef MVPN_DEBUG +# define MVPN_COUNT_CTOR(_type) \ + do { \ + static_assert(std::is_class<_type>(), \ + "Token '" #_type "' is not a class type."); \ + LeakDetector::logCtor((void*)this, #_type, sizeof(*this)); \ + } while (0) + +# define MVPN_COUNT_DTOR(_type) \ + do { \ + static_assert(std::is_class<_type>(), \ + "Token '" #_type "' is not a class type."); \ + LeakDetector::logDtor((void*)this, #_type, sizeof(*this)); \ + } while (0) + +#else +# define MVPN_COUNT_CTOR(_type) +# define MVPN_COUNT_DTOR(_type) +#endif + +class LeakDetector { + public: + LeakDetector(); + ~LeakDetector(); + +#ifdef MVPN_DEBUG + static void logCtor(void* ptr, const char* typeName, uint32_t size); + static void logDtor(void* ptr, const char* typeName, uint32_t size); +#endif +}; + +#endif // LEAKDETECTOR_H diff --git a/client/platforms/linux/linuxsystemtraynotificationhandler.cpp b/client/platforms/linux/linuxsystemtraynotificationhandler.cpp index 408eef49..bc4fda36 100644 --- a/client/platforms/linux/linuxsystemtraynotificationhandler.cpp +++ b/client/platforms/linux/linuxsystemtraynotificationhandler.cpp @@ -18,7 +18,7 @@ namespace { Logger logger(LOG_LINUX, "LinuxSystemTrayNotificationHandler"); } // namespace -// static +//static bool LinuxSystemTrayNotificationHandler::requiredCustomImpl() { if (!QDBusConnection::sessionBus().isConnected()) { return false; diff --git a/client/ui/notificationhandler.cpp b/client/ui/notificationhandler.cpp index 4a4f3c5f..59054287 100644 --- a/client/ui/notificationhandler.cpp +++ b/client/ui/notificationhandler.cpp @@ -27,7 +27,7 @@ NotificationHandler* NotificationHandler::create(QObject* parent) { #else # if defined(Q_OS_LINUX) - if (LinuxSystemTrayNotificationHandler::requiredCustomImpl()) { + if (LinuxSystemTrayNotificationHandler::requiredCustomImpl() == true) { return new LinuxSystemTrayNotificationHandler(parent); } # endif diff --git a/client/ui/pages_logic/ShareConnectionLogic.cpp b/client/ui/pages_logic/ShareConnectionLogic.cpp index a5a1610e..038b3891 100644 --- a/client/ui/pages_logic/ShareConnectionLogic.cpp +++ b/client/ui/pages_logic/ShareConnectionLogic.cpp @@ -25,6 +25,10 @@ #include "../uilogic.h" +#ifdef __linux__ + #include +#endif + ShareConnectionLogic::ShareConnectionLogic(UiLogic *logic, QObject *parent): PageLogicBase(logic, parent), m_textEditShareOpenVpnCodeText{},