chiark / gitweb /
fwd: Improve `source' and `target' lifecycle management.
[fwd] / exec.c
diff --git a/exec.c b/exec.c
index d41a31d075cdb6b2e054c9a5e6d5b9043230ded9..fc8b679795ff6e81c868d37d3650640293114e16 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -1004,6 +1004,8 @@ static source *xsource_read(scanner *sc)
     return (0);
   xs = CREATE(xsource);
   xs->s.ops = &xsource_ops;
+  xs->s.ref = 1;
+  xs->s.f = 0;
   xs->s.desc = 0;
   exec_read(&xs->x, sc);
   return (&xs->s);
@@ -1032,18 +1034,12 @@ static void xsource_attach(source *s, scanner *sc, target *t)
   /* --- Create the endpoints --- */
 
   if ((ee = t->ops->create(t, xs->s.desc)) == 0)
-    goto tidy;
+    return;
   if ((e = exec_endpt(&xs->x, xs->s.desc)) == 0) {
     ee->ops->close(ee);
-    goto tidy;
+    return;
   }
   endpt_join(e, ee, xs->s.desc);
-
-  /* --- Dispose of source and target --- */
-
-tidy:
-  t->ops->destroy(t);
-  xsource_destroy(&xs->s);
 }
 
 /* --- @destroy@ --- */
@@ -1060,7 +1056,7 @@ static void xsource_destroy(source *s)
 
 source_ops xsource_ops = {
   "exec",
-  xsource_option, xsource_read, xsource_attach, xsource_destroy
+  xsource_option, xsource_read, xsource_attach, 0, xsource_destroy
 };
 
 /*----- Exec target description -------------------------------------------*/
@@ -1084,6 +1080,7 @@ static target *xtarget_read(scanner *sc)
     return (0);
   xt = CREATE(xtarget);
   xt->t.ops = &xtarget_ops;
+  xt->t.ref = 1;
   exec_read(&xt->x, sc);
   exec_desc(&xt->x, &d);
   xt->t.desc = xstrdup(d.buf);