From: Andre Noll Date: Thu, 30 Jan 2014 21:49:45 +0000 (+0100) Subject: ao_write: Fix spurious segfault. X-Git-Tag: v0.5.3~20^2~8 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=751e3811e99c744f9f651b191950010ce118eb78 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. --- 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);