Fix a few minor leaks (or just memory showing up as not freed in tools)

This commit is contained in:
Nicolas Werner 2023-01-22 05:01:50 +01:00
parent 2157ebb614
commit 7f9af9016d
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
4 changed files with 28 additions and 5 deletions

View file

@ -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();

View file

@ -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;
}

View file

@ -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
{

View file

@ -46,4 +46,5 @@ private:
public:
CallDevices(CallDevices const &) = delete;
void operator=(CallDevices const &) = delete;
void deinit();
};