From 751e3811e99c744f9f651b191950010ce118eb78 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 30 Jan 2014 22:49:45 +0100 Subject: [PATCH] ao_write: Fix spurious segfault. Both btr_node_status() and btr_consume() access the buffer tree of the ao writer, so these functions must be called with the pthread mutex locked. --- ao_write.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ao_write.c b/ao_write.c index 730653c1..52c4b11e 100644 --- a/ao_write.c +++ b/ao_write.c @@ -48,7 +48,14 @@ static void aow_close(struct writer_node *wn) static void aow_pre_select(struct sched *s, struct task *t) { struct writer_node *wn = container_of(t, struct writer_node, task); - int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF); + struct private_aow_data *pawd = wn->private_data; + int ret; + + if (pawd) + pthread_mutex_lock(&pawd->mutex); + ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF); + if (pawd) + pthread_mutex_unlock(&pawd->mutex); if (ret == 0) return; @@ -223,7 +230,9 @@ __noreturn static void *aow_play(void *priv) ret = -E_AO_PLAY; if (ao_play(pawd->dev, data, bytes) == 0) /* failure */ goto out; + pthread_mutex_lock(&pawd->mutex); btr_consume(btrn, bytes); + pthread_mutex_unlock(&pawd->mutex); } unlock: pthread_mutex_unlock(&pawd->mutex); -- 2.39.2