summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2023-01-22 05:01:50 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2023-01-22 05:02:10 +0100
commit7f9af9016d2e5a5513457e191bc454885561a73a (patch)
tree6e02e5961341868bc32b5dab4cbd8a612e426919 /src
parentMerge pull request #1304 from Decodetalkers/imagesave (diff)
downloadnheko-7f9af9016d2e5a5513457e191bc454885561a73a.tar.xz
Fix a few minor leaks (or just memory showing up as not freed in tools)
Diffstat (limited to '')
-rw-r--r--src/Utils.cpp5
-rw-r--r--src/main.cpp14
-rw-r--r--src/voip/CallDevices.cpp13
-rw-r--r--src/voip/CallDevices.h1
4 files changed, 28 insertions, 5 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 8ad84e85..c23043a8 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -598,7 +598,7 @@ utils::markdownToHtml(const QString &text, bool rainbowify)
         int charIdx = 0;
         while (cmark_iter_next(iter) != CMARK_EVENT_DONE) {
             cmark_node *cur = cmark_iter_get_node(iter);
-            // only text nodes (no code or semilar)
+            // only text nodes (no code or similar)
             if (cmark_node_get_type(cur) != CMARK_NODE_TEXT)
                 continue;
 
@@ -608,7 +608,7 @@ utils::markdownToHtml(const QString &text, bool rainbowify)
             QString buf;
             int boundaryStart = 0;
             int boundaryEnd   = 0;
-            // use QTextBoundaryFinder to iterate ofer graphemes
+            // use QTextBoundaryFinder to iterate over graphemes
             QTextBoundaryFinder tbf(QTextBoundaryFinder::BoundaryType::Grapheme, nodeText);
             while ((boundaryEnd = tbf.toNextBoundary()) != -1) {
                 charIdx++;
@@ -654,6 +654,7 @@ utils::markdownToHtml(const QString &text, bool rainbowify)
 
     // The buffer is no longer needed.
     free((char *)tmp_buf);
+    cmark_node_free(node);
 
     auto result = linkifyMessage(escapeBlacklistedHtml(QString::fromStdString(html))).trimmed();
 
diff --git a/src/main.cpp b/src/main.cpp
index 9973b03b..779c7800 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -37,9 +37,11 @@
 #include "notifications/Manager.h"
 #endif
 
-#if defined(GSTREAMER_AVAILABLE) && (defined(Q_OS_MAC) || defined(Q_OS_WINDOWS))
+#ifdef GSTREAMER_AVAILABLE
 #include <QAbstractEventDispatcher>
 #include <gst/gst.h>
+
+#include "voip/CallDevices.h"
 #endif
 
 #ifdef QML_DEBUGGING
@@ -399,5 +401,13 @@ main(int argc, char *argv[])
 
     nhlog::ui()->info("starting nheko {}", nheko::version);
 
-    return app.exec();
+    auto returnvalue = app.exec();
+
+#ifdef GSTREAMER_AVAILABLE
+    CallDevices::instance().deinit();
+
+    gst_deinit();
+#endif
+
+    return returnvalue;
 }
diff --git a/src/voip/CallDevices.cpp b/src/voip/CallDevices.cpp
index e47b5960..ee9a7f43 100644
--- a/src/voip/CallDevices.cpp
+++ b/src/voip/CallDevices.cpp
@@ -248,10 +248,11 @@ tokenise(std::string_view str, char delim)
 }
 }
 
+static GstDeviceMonitor *monitor = nullptr;
+
 void
 CallDevices::init()
 {
-    static GstDeviceMonitor *monitor = nullptr;
     if (!monitor) {
         monitor       = gst_device_monitor_new();
         GstCaps *caps = gst_caps_new_empty_simple("audio/x-raw");
@@ -273,6 +274,16 @@ CallDevices::init()
     }
 }
 
+void
+CallDevices::deinit()
+{
+    if (monitor) {
+        gst_device_monitor_stop(monitor);
+        g_free(monitor);
+        monitor = nullptr;
+    }
+}
+
 bool
 CallDevices::haveMic() const
 {
diff --git a/src/voip/CallDevices.h b/src/voip/CallDevices.h
index 951f1ab2..d18ccfb3 100644
--- a/src/voip/CallDevices.h
+++ b/src/voip/CallDevices.h
@@ -46,4 +46,5 @@ private:
 public:
     CallDevices(CallDevices const &)    = delete;
     void operator=(CallDevices const &) = delete;
+    void deinit();
 };