]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
ao_write: Fix spurious segfault.
authorAndre Noll <maan@systemlinux.org>
Thu, 30 Jan 2014 21:49:45 +0000 (22:49 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 6 Apr 2014 06:53:25 +0000 (08:53 +0200)
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

index 730653c1b06844ed0822cc784c0c61b6a0303269..52c4b11e1a11c51a419bb32bbc58c6052c7221cd 100644 (file)
@@ -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);