wng: fix two critical bugs
authorAndre <maan@p133.(none)>
Mon, 29 May 2006 22:56:35 +0000 (00:56 +0200)
committerAndre <maan@p133.(none)>
Mon, 29 May 2006 22:56:35 +0000 (00:56 +0200)
the open functions of the writers in a writer node group
might be interested to know which group they belong to.
Unfortunately, the old code called open before initializing
the "wng" pointer of the writer node.

The second bug triggers for example if invalid receiver options are
given. In this case wng_close() is called with a NULL-argument as
the wng has not been opened yet. The solution is to check for NULL
pointers and return immediately in this case.

write_common.c

index cfdabe4..39f124f 100644 (file)
@@ -58,15 +58,15 @@ int wng_open(struct writer_node_group *g)
 {
        int i, ret = 1;
 
-       PARA_NOTICE_LOG("opening wng with %d writer(s)\n", g->num_writers);
+       PARA_NOTICE_LOG("opening wng %p with %d writer(s)\n", g, g->num_writers);
        FOR_EACH_WRITER_NODE(i, g) {
                struct writer_node *wn = &g->writer_nodes[i];
+               wn->wng = g;
                ret = wn->writer->open(wn);
                if (ret < 0)
                        goto out;
                wn->chunk_bytes = ret;
                g->max_chunk_bytes = PARA_MAX(g->max_chunk_bytes, ret);
-               wn->wng = g;
                PARA_DEBUG_LOG("pre_select: %p\n", &wn->writer->pre_select);
                PARA_DEBUG_LOG("post_select: %p\n", &wn->writer->post_select);
                wn->task.pre_select = wn->writer->pre_select;
@@ -94,6 +94,8 @@ void wng_close(struct writer_node_group *g)
 {
        int i;
 
+       if (!g)
+               return;
        PARA_NOTICE_LOG("closing wng with %d writer(s)\n", g->num_writers);
        FOR_EACH_WRITER_NODE(i, g) {
                struct writer_node *wn = &g->writer_nodes[i];