Skip to content

Commit f2c3f05

Browse files
committed
Fix a potential crash with builds using older PipeWire headers
1 parent a9cdd5f commit f2c3f05

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

alc/backends/pipewire.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,30 @@ auto as_const_ptr(T *ptr) noexcept -> std::add_const_t<T>* { return ptr; }
144144

145145
struct SpaHook : spa_hook {
146146
SpaHook() : spa_hook{} { }
147-
~SpaHook() { spa_hook_remove(this); }
147+
~SpaHook()
148+
{
149+
/* Prior to 0.3.57, spa_hook_remove will crash if the spa_hook hasn't
150+
* been linked with anything, which complicates removing on destruction
151+
* since the spa_hook object needs to exist before it's linked, but if
152+
* linking fails, there's no function to test if it can be removed. The
153+
* PipeWire headers say spa_hook should be treated as opaque, meaning
154+
* accessing any fields directly risks breaking compilation in the
155+
* future. So we only peek into the spa_hool to do this check on older
156+
* versions that need it.
157+
*/
158+
#if !PW_CHECK_VERSION(0,3,57)
159+
if(this->link.prev != nullptr)
160+
#endif
161+
spa_hook_remove(this);
162+
}
148163

149164
void remove()
150165
{
151-
spa_hook_remove(this);
152-
static_cast<spa_hook&>(*this) = {};
166+
#if !PW_CHECK_VERSION(0,3,57)
167+
if(this->link.prev != nullptr)
168+
#endif
169+
spa_hook_remove(this);
170+
static_cast<spa_hook&>(*this) = spa_hook{};
153171
}
154172

155173
SpaHook(const SpaHook&) = delete;

0 commit comments

Comments
 (0)