Fix wng_open error handling.
[paraslash.git] / write_common.c
index dda6016..a413d47 100644 (file)
@@ -66,7 +66,7 @@ int wng_open(struct writer_node_group *g)
                wn->wng = g;
                ret = wn->writer->open(wn);
                if (ret < 0)
-                       goto out;
+                       goto err_out;
                wn->chunk_bytes = ret;
                g->max_chunk_bytes = PARA_MAX(g->max_chunk_bytes, ret);
                wn->task.pre_select = wn->writer->pre_select;
@@ -75,9 +75,17 @@ int wng_open(struct writer_node_group *g)
                register_task(&wn->task);
        }
        sprintf(g->task.status, "%s", "writer node group");
-       g->eof = 0;
        register_task(&g->task);
-out:
+       g->eof = 0;
+       return 1;
+err_out:
+       while (i > 0) {
+               struct writer_node *wn = &g->writer_nodes[--i];
+               unregister_task(&wn->task);
+               wn->writer->close(wn);
+       }
+       g->num_writers = 0;
+       g->eof = 1;
        return ret;
 }