Revert "Fix potential memory leaks"

This commit is contained in:
Alexis Rouillard
2023-10-22 09:44:46 +02:00
committed by GitHub
parent dbb887b4a9
commit 2d33c20231
13 changed files with 29 additions and 90 deletions

View File

@ -2,8 +2,6 @@
#include <spdlog/spdlog.h>
#include "util/scope_guard.hpp"
namespace waybar::modules::SNI {
Host::Host(const std::size_t id, const Json::Value& config, const Bar& bar,
@ -59,20 +57,17 @@ void Host::nameVanished(const Glib::RefPtr<Gio::DBus::Connection>& conn, const G
void Host::proxyReady(GObject* src, GAsyncResult* res, gpointer data) {
GError* error = nullptr;
waybar::util::scope_guard error_deleter([error]() {
if (error != nullptr) {
g_error_free(error);
}
});
SnWatcher* watcher = sn_watcher_proxy_new_finish(res, &error);
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
spdlog::error("Host: {}", error->message);
g_error_free(error);
return;
}
auto host = static_cast<SNI::Host*>(data);
host->watcher_ = watcher;
if (error != nullptr) {
spdlog::error("Host: {}", error->message);
g_error_free(error);
return;
}
sn_watcher_call_register_host(host->watcher_, host->object_path_.c_str(), host->cancellable_,
@ -81,19 +76,16 @@ void Host::proxyReady(GObject* src, GAsyncResult* res, gpointer data) {
void Host::registerHost(GObject* src, GAsyncResult* res, gpointer data) {
GError* error = nullptr;
waybar::util::scope_guard error_deleter([error]() {
if (error != nullptr) {
g_error_free(error);
}
});
sn_watcher_call_register_host_finish(SN_WATCHER(src), res, &error);
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
spdlog::error("Host: {}", error->message);
g_error_free(error);
return;
}
auto host = static_cast<SNI::Host*>(data);
if (error != nullptr) {
spdlog::error("Host: {}", error->message);
g_error_free(error);
return;
}
g_signal_connect(host->watcher_, "item-registered", G_CALLBACK(&Host::itemRegistered), data);

View File

@ -2,8 +2,6 @@
#include <spdlog/spdlog.h>
#include "util/scope_guard.hpp"
using namespace waybar::modules::SNI;
Watcher::Watcher()
@ -31,11 +29,6 @@ Watcher::~Watcher() {
void Watcher::busAcquired(const Glib::RefPtr<Gio::DBus::Connection>& conn, Glib::ustring name) {
GError* error = nullptr;
waybar::util::scope_guard error_deleter([error]() {
if (error) {
g_error_free(error);
}
});
g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(watcher_), conn->gobj(),
"/StatusNotifierWatcher", &error);
if (error != nullptr) {
@ -43,6 +36,7 @@ void Watcher::busAcquired(const Glib::RefPtr<Gio::DBus::Connection>& conn, Glib:
if (error->code != 2) {
spdlog::error("Watcher: {}", error->message);
}
g_error_free(error);
return;
}
g_signal_connect_swapped(watcher_, "handle-register-item",