From 4a562d17319e990f75ea3bbf5f3e25bfe0aafba7 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 12 Jul 2008 12:40:36 +0200 Subject: [PATCH] Fix a bug in para_write. 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 | 2 ++ write_common.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/write.h b/write.h index a73ada5d..091f8c77 100644 --- 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 */ diff --git a/write_common.c b/write_common.c index 70a9a015..3bf5d119 100644 --- a/write_common.c +++ b/write_common.c @@ -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) { -- 2.39.2