]> xenbits.xensource.com Git - xen.git/commitdiff
libxl: close fd's in parent when spawning qdisk
authorIan Campbell <ian.campbell@citrix.com>
Tue, 16 Feb 2016 11:49:53 +0000 (11:49 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 16 Feb 2016 17:42:53 +0000 (17:42 +0000)
Coverity points out that these remain open in the parent upon
success, which is a resource leak.

To fix this rejig the exit paths such that success and error cases
both close the two fds, this means adjusting the callback to only
happen for the error case and it also makes sense to rename the label
from "error" to just "out".

Compile tested only.

CID: 1130518 (null) and 1130517 (logfile_w).

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/libxl/libxl_dm.c

index a088d71160903aca4f7522a0867e8c42556a015d..4aca38e2897424e57d0c7116591a1174cc689886 100644 (file)
@@ -1999,12 +1999,12 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)
     logfile_w = libxl__create_qemu_logfile(gc, GCSPRINTF("qdisk-%u", domid));
     if (logfile_w < 0) {
         rc = logfile_w;
-        goto error;
+        goto out;
     }
     null = open("/dev/null", O_RDONLY);
     if (null < 0) {
        rc = ERROR_FAIL;
-       goto error;
+       goto out;
     }
 
     dmss->guest_config = NULL;
@@ -2030,19 +2030,18 @@ void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__dm_spawn_state *dmss)
     dmss->spawn.detached_cb = device_model_detached;
     rc = libxl__spawn_spawn(egc, &dmss->spawn);
     if (rc < 0)
-        goto error;
+        goto out;
     if (!rc) { /* inner child */
         setsid();
         libxl__exec(gc, null, logfile_w, logfile_w, dm, args, NULL);
     }
 
-    return;
-
-error:
-    assert(rc);
+    rc = 0;
+out:
     if (logfile_w >= 0) close(logfile_w);
     if (null >= 0) close(null);
-    dmss->callback(egc, dmss, rc);
+    /* callback on error only, success goes via dmss->spawn.*_cb */
+    if (rc) dmss->callback(egc, dmss, rc);
     return;
 }