xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] init-xenstore-domain: cleanup all resources on a single exit path
@ 2016-02-10 16:56 Ian Campbell
  2016-02-11 11:27 ` Wei Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Campbell @ 2016-02-10 16:56 UTC (permalink / raw)
  To: Daniel De Graaf, ian.jackson, wei.liu2, xen-devel; +Cc: Ian Campbell

Previously xs_fd would be left open, which is CID 1055993 (previously
partially fixed by 3bca826aae5eb).

Instead arrange for both success and error cases to cleanup everything
on a single exit path instead of doing partial cleanup on the success
path a few operations higher up.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/helpers/init-xenstore-domain.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
index 5c5af2d..909542b 100644
--- a/tools/helpers/init-xenstore-domain.c
+++ b/tools/helpers/init-xenstore-domain.c
@@ -172,9 +172,6 @@ static int build(xc_interface *xch)
         goto err;
     }
 
-    xc_dom_release(dom);
-    dom = NULL;
-
     rv = xc_domain_set_virq_handler(xch, domid, VIRQ_DOM_EXC);
     if ( rv )
     {
@@ -188,14 +185,18 @@ static int build(xc_interface *xch)
         goto err;
     }
 
-    return 0;
+    rv = 0;
 
 err:
     if ( dom )
         xc_dom_release(dom);
-    if ( domid != ~0 )
+    if ( xs_fd >= 0 )
+        close(xs_fd);
+
+    /* if we failed then destroy the domain */
+    if ( rv && domid != ~0 )
         xc_domain_destroy(xch, domid);
-    close(xs_fd);
+
     return rv;
 }
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-02-11 15:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-10 16:56 [PATCH] init-xenstore-domain: cleanup all resources on a single exit path Ian Campbell
2016-02-11 11:27 ` Wei Liu
2016-02-11 15:38   ` Ian Campbell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).