By delaying freeing the XLU_Config object until the end we miss doing
so on various success and error paths.

Instead free it as soon as the parsing is complete and ensure that
parse errors come through this path by exiting the loop early and
handling that error after the free instead of returning directly from
the loop.

Compile tested only.

CID: 1055902

Signed-off-by: Ian Campbell <ian.campb...@citrix.com>
---
v2: Move NULL assignment here from "xl: free config_data on error in
    domain_create" where it didn't belong.
v1: Not posted.
---
 tools/libxl/xl_cmdimpl.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index d1f36f8..9f08f64 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -6524,9 +6524,14 @@ int main_networkattach(int argc, char **argv)
 
     for (argv += optind+1, argc -= optind+1; argc > 0; ++argv, --argc) {
         if (parse_nic_config(&nic, &config, *argv))
-            return 1;
+            break;
     }
 
+    xlu_cfg_destroy(config);
+    config = NULL;
+
+    if (argc > 0) return 1; /* Parse error above */
+
     if (dryrun_only) {
         char *json = libxl_device_nic_to_json(ctx, &nic);
         printf("vif: %s\n", json);
@@ -6541,7 +6546,6 @@ int main_networkattach(int argc, char **argv)
         return 1;
     }
     libxl_device_nic_dispose(&nic);
-    xlu_cfg_destroy(config);
     return 0;
 }
 
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

Reply via email to