Revert "Revert "Fix potential memory leaks""

This reverts commit 2d33c20231 and
reapplies various patches for memory leaks.
The reason for the revert was a bug for a maximum duration interval
which caused sleep_for() to cause unpredictable behavior.
This commit is contained in:
Tamino Bauknecht
2023-10-23 01:14:52 +02:00
parent 521dac8086
commit dd1de3efbf
13 changed files with 90 additions and 29 deletions

View File

@ -69,7 +69,7 @@ class UPower : public AModule {
UpDevice *displayDevice;
guint login1_id;
GDBusConnection *login1_connection;
UPowerTooltip *upower_tooltip;
std::unique_ptr<UPowerTooltip> upower_tooltip;
std::string lastStatus;
bool showAltText;
bool upowerRunning;

View File

@ -2,6 +2,7 @@
#include <libupower-glib/upower.h>
#include <memory>
#include <unordered_map>
#include "gtkmm/box.h"
@ -16,7 +17,7 @@ class UPowerTooltip : public Gtk::Window {
const std::string getDeviceIcon(UpDeviceKind& kind);
Gtk::Box* contentBox;
std::unique_ptr<Gtk::Box> contentBox;
uint iconSize;
uint tooltipSpacing;

View File

@ -0,0 +1,21 @@
#pragma once
#include <utility>
namespace waybar::util {
template <typename Func>
class scope_guard {
public:
explicit scope_guard(Func&& exit_function) : f{std::forward<Func>(exit_function)} {}
scope_guard(const scope_guard&) = delete;
scope_guard(scope_guard&&) = default;
scope_guard& operator=(const scope_guard&) = delete;
scope_guard& operator=(scope_guard&&) = default;
~scope_guard() { f(); }
private:
Func f;
};
} // namespace waybar::util