Skip to contentSkip to conversation

init-xenstore-domain: cleanup all resources on a single exit path

PATCH In review Ian Campbell 2 participants 3 messages Feb 10, 2016 – Feb 11, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 init-xenstore-domain: cleanup all resources on a single exit path

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.

---
 tools/helpers/init-xenstore-domain.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
tools/helpers/init-xenstore-domain.c +7 -6
index 5c5af2d..909542b 100644
@@ -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;
 }
 
Signature · 1 line
2.1.4
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · 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.

Quoted 43 lines
---
 tools/helpers/init-xenstore-domain.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
tools/helpers/init-xenstore-domain.c +7 -6
index 5c5af2d..909542b 100644
@@ -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;
 }
 
Signature · 1 line
2.1.4
author Applied
#2 lore raw
Quoted 11 lines · Wei Liu
Quoted 8 lines · 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.

Thanks, applied.