Merge pull request #2265 from tengyifei/master

Partially revert 3af1853260 to fix use-after-free
This commit is contained in:
Alexis Rouillard 2023-07-04 22:59:45 +02:00 committed by GitHub
commit 5ef6636237
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -19,9 +19,13 @@ Host::Host(const std::size_t id, const Json::Value& config, const Bar& bar,
Host::~Host() { Host::~Host() {
if (bus_name_id_ > 0) { if (bus_name_id_ > 0) {
Gio::DBus::unwatch_name(bus_name_id_); Gio::DBus::unown_name(bus_name_id_);
bus_name_id_ = 0; bus_name_id_ = 0;
} }
if (watcher_id_ > 0) {
Gio::DBus::unwatch_name(watcher_id_);
watcher_id_ = 0;
}
g_cancellable_cancel(cancellable_); g_cancellable_cancel(cancellable_);
g_clear_object(&cancellable_); g_clear_object(&cancellable_);
g_clear_object(&watcher_); g_clear_object(&watcher_);

View File

@ -14,6 +14,10 @@ Watcher::Watcher()
watcher_(sn_watcher_skeleton_new()) {} watcher_(sn_watcher_skeleton_new()) {}
Watcher::~Watcher() { Watcher::~Watcher() {
if (hosts_ != nullptr) {
g_slist_free_full(hosts_, gfWatchFree);
hosts_ = nullptr;
}
if (items_ != nullptr) { if (items_ != nullptr) {
g_slist_free_full(items_, gfWatchFree); g_slist_free_full(items_, gfWatchFree);
items_ = nullptr; items_ = nullptr;