Skip to content

Commit 91dcb41

Browse files
committed
services/pipewire: destroy qml ifaces early to avoid user callbacks
Consumers of defaultAudio*Changed signals can run code between safeDestroy being called and PwObjectIface destruction due to signal connection order. This change destroys ifaces earlier so they are nulled by the time a changed signal is fired from destruction, preventing access between ~PwNode() and ~QObject() completion. Fixes #116 #122 #124
1 parent 201c559 commit 91dcb41

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/services/pipewire/qml.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818

1919
namespace qs::service::pipewire {
2020

21+
PwObjectIface::PwObjectIface(PwBindableObject* object): QObject(object), object(object) {
22+
// We want to destroy the interface before QObject::destroyed is fired, as handlers
23+
// connected before PwObjectIface will run first and emit signals that hit user code,
24+
// which can then try to reference the iface again after ~PwNode() has been called but
25+
// before ~QObject() has finished.
26+
QObject::connect(object, &PwBindableObject::destroying, this, &PwObjectIface::onObjectDestroying);
27+
}
28+
29+
void PwObjectIface::onObjectDestroying() { delete this; }
30+
2131
void PwObjectIface::ref() {
2232
this->refcount++;
2333

src/services/pipewire/qml.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ class PwObjectIface
3636
Q_OBJECT;
3737

3838
public:
39-
explicit PwObjectIface(PwBindableObject* object): QObject(object), object(object) {};
39+
explicit PwObjectIface(PwBindableObject* object);
4040
// destructor should ONLY be called by the pw object destructor, making an unref unnecessary
4141
~PwObjectIface() override = default;
4242
Q_DISABLE_COPY_MOVE(PwObjectIface);
4343

4444
void ref() override;
4545
void unref() override;
4646

47+
private slots:
48+
void onObjectDestroying();
49+
4750
private:
4851
quint32 refcount = 0;
4952
PwBindableObject* object;

0 commit comments

Comments
 (0)