Skip to content

Commit 27b203f

Browse files
committed
fixed memory leak on reload
1 parent 2f505f9 commit 27b203f

6 files changed

Lines changed: 37 additions & 8 deletions

File tree

src/panel/widgets/wp-mixer/wf-wp-control.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ WfWpControl::WfWpControl(WpPipewireObject *obj, WayfireWpMixer *parent_widget)
1010
parent = parent_widget;
1111
}
1212

13+
WfWpControl::~WfWpControl()
14+
{
15+
mute_conn.disconnect();
16+
middle_conn.disconnect();
17+
right_conn.disconnect();
18+
for (auto signal : signals)
19+
{
20+
signal.disconnect();
21+
}
22+
}
23+
1324
void WfWpControl::init()
1425
{
1526
guint32 id = wp_proxy_get_bound_id(WP_PROXY(object));
@@ -53,7 +64,7 @@ void WfWpControl::init()
5364

5465
// setup user interactions
5566

56-
mute_conn = button.signal_toggled().connect(
67+
signals.push_back(mute_conn = button.signal_toggled().connect(
5768
[this, id] ()
5869
{
5970
// if the menu was popped up because of an external change
@@ -63,7 +74,7 @@ void WfWpControl::init()
6374
// disregarding the return value prevents cases where ignore is read at an ncorrect time,
6475
// with the only problem of having one update ignored if something goes very wrong
6576
WpCommon::get().set_mute(id, button.get_active());
66-
});
77+
}));
6778

6879
scale.set_user_changed_callback(
6980
[this, id] ()
@@ -74,7 +85,7 @@ void WfWpControl::init()
7485
});
7586

7687
auto scroll_gesture = Gtk::EventControllerScroll::create();
77-
scroll_gesture->signal_scroll().connect([=] (double dx, double dy)
88+
signals.push_back(scroll_gesture->signal_scroll().connect([=] (double dx, double dy)
7889
{
7990
dy = parent->invert_scroll ? dy : dy * -1; // for the same scrolling as volume widget, which we will
8091
// agree it is more intuitive for more people
@@ -92,7 +103,7 @@ void WfWpControl::init()
92103

93104
WpCommon::get().set_volume(id, scale.get_target_value() + change);
94105
return true;
95-
}, true);
106+
}, true));
96107
scroll_gesture->set_flags(Gtk::EventControllerScroll::Flags::VERTICAL);
97108
add_controller(scroll_gesture);
98109

@@ -200,6 +211,11 @@ std::unique_ptr<WfWpControl> WfWpControl::copy()
200211
return std::make_unique<WfWpControl>(object, parent);
201212
}
202213

214+
WfWpControlDevice::~WfWpControlDevice()
215+
{
216+
def_conn.disconnect();
217+
}
218+
203219
void WfWpControlDevice::init()
204220
{
205221
default_btn.get_style_context()->add_class("wireplumber");

src/panel/widgets/wp-mixer/wf-wp-control.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ class WfWpControl : public Gtk::Grid
1919
WayfireWpMixer *parent;
2020
std::shared_ptr<Gtk::GestureClick> middle_click_mute, right_click_mute;
2121
sigc::connection middle_conn, right_conn;
22+
std::vector<sigc::connection> signals;
2223
void update_gestures();
2324
virtual void update_icons_pos();
2425
WfOption<int> slider_length{"panel/wp_slider_length"};
2526

2627
public:
2728
WfWpControl(WpPipewireObject *obj, WayfireWpMixer *parent_widget);
29+
~WfWpControl();
2830
virtual void init();
2931

3032
WpPipewireObject *object;
@@ -49,13 +51,15 @@ class WfWpControl : public Gtk::Grid
4951
class WfWpControlDevice : public WfWpControl
5052
{
5153
private:
54+
5255
sigc::connection def_conn;
5356
Gtk::Image is_def_icon;
5457
void update_icons_pos();
5558

5659
public:
5760
WfWpControlDevice(WpPipewireObject *obj, WayfireWpMixer *parent_widget) : WfWpControl(obj, parent_widget)
5861
{}
62+
~WfWpControlDevice();
5963
void init();
6064

6165
Gtk::ToggleButton default_btn;

src/panel/widgets/wp-mixer/wp-mixer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void WayfireWpMixer::init(Gtk::Box *container)
217217

218218
// scroll to change volume of the object targetted by the quick_target widget
219219
auto scroll_gesture = Gtk::EventControllerScroll::create();
220-
scroll_gesture->signal_scroll().connect([=] (double dx, double dy)
220+
scroll_conn = scroll_gesture->signal_scroll().connect([=] (double dx, double dy)
221221
{
222222
if (!quick_target)
223223
{
@@ -345,4 +345,9 @@ WayfireWpMixer::~WayfireWpMixer()
345345
WpCommon::get().rem_widget(this);
346346
gtk_widget_unparent(GTK_WIDGET(popover->gobj()));
347347
popover_timeout.disconnect();
348+
volume_changed_signal.disconnect();
349+
left_conn.disconnect();
350+
middle_conn.disconnect();
351+
right_conn.disconnect();
352+
scroll_conn.disconnect();
348353
}

src/panel/widgets/wp-mixer/wp-mixer.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ class WayfireWpMixer : public WayfireWidget
3838
gulong notify_volume_signal = 0;
3939
gulong notify_is_muted_signal = 0;
4040
gulong notify_default_sink_changed = 0;
41-
sigc::connection popover_timeout;
42-
sigc::connection volume_changed_signal;
41+
sigc::connection popover_timeout, volume_changed_signal, left_conn, middle_conn, right_conn, scroll_conn;
4342
std::shared_ptr<Gtk::GestureClick> left_click_gesture, middle_click_gesture, right_click_gesture;
44-
sigc::connection left_conn, middle_conn, right_conn;
4543

4644
// widgets for the mixer itself
4745
Gtk::Label output_label, input_label, streams_label;

src/util/animated-scale.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ WayfireAnimatedScale::WayfireAnimatedScale()
1313
});
1414
}
1515

16+
WayfireAnimatedScale::~WayfireAnimatedScale()
17+
{
18+
value_changed.disconnect();
19+
}
20+
1621
void WayfireAnimatedScale::set_target_value(double value)
1722
{
1823
this->current_volume.animate(value);

src/util/animated-scale.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class WayfireAnimatedScale : public Gtk::Scale
1717

1818
public:
1919
WayfireAnimatedScale();
20+
~WayfireAnimatedScale();
2021

2122
/* Gets the current target value */
2223
double get_target_value() const;

0 commit comments

Comments
 (0)