Fix a bug in para_write.
authorAndre Noll <maan@systemlinux.org>
Sat, 12 Jul 2008 10:40:36 +0000 (12:40 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 12 Jul 2008 10:40:36 +0000 (12:40 +0200)
With the old code, the command "para_write < /dev/null" would
segfault because the wng_close() is called although the writer
node group was never opened. Fix this bug by introducing a new
field in struct writer_node_group that tracks whether wng_open()
was called.

write.h
write_common.c

diff --git a/write.h b/write.h
index a73ada5..091f8c7 100644 (file)
--- a/write.h
+++ b/write.h
@@ -113,6 +113,8 @@ struct writer_node_group {
        unsigned int *samplerate;
        /** the task associated to this group */
        struct task task;
+       /** Whether the group is open, i.e. wng_open() was called. */
+       int open;
 };
 
 /** loop over each writer node in a writer group */
index 70a9a01..3bf5d11 100644 (file)
@@ -90,6 +90,7 @@ int wng_open(struct writer_node_group *g)
        }
        sprintf(g->task.status, "%s", "writer node group");
        register_task(&g->task);
+       g->open = 1;
        return 1;
 err_out:
        PARA_ERROR_LOG("%s\n", para_strerror(-ret));
@@ -112,7 +113,7 @@ void wng_close(struct writer_node_group *g)
 {
        int i;
 
-       if (!g)
+       if (!g || !g->open)
                return;
        PARA_NOTICE_LOG("closing wng with %d writer(s)\n", g->num_writers);
        FOR_EACH_WRITER_NODE(i, g) {