xl: network-attach: free config object after use
PATCH v2 1/2 xl: network-attach: free config object after use
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 <[email protected]>
---
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(-)
tools/libxl/xl_cmdimpl.c +6 -2
@@ -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 ; }
Signature · 1 line
2.1.4
PATCH v2 2/2 xl: free config_data on error in domain_create
CID: 1055898
Signed-off-by Ian Campbell <[email protected]>
---
v2: Move spurious looking NULL assignment to previous patch where it
belongs.
--- tools/libxl/xl_cmdimpl.c | 1 + 1 file changed, 1 insertion(+)
tools/libxl/xl_cmdimpl.c +1 -0
@@ -2795,6 +2795,7 @@ static uint32_t create_domain(struct domain_create *dom_info)if (!restoring && extra_config &&strlen (extra_config)) {if (config_len >INT_MAX - (strlen (extra_config) +2 +1 )) {fprintf (stderr,"Failed to attach extra configuration\n" ); +free (config_data);return ERROR_FAIL ; }/* allocate space for the extra config plus two EOLs plus \0 */
Signature · 1 line
2.1.4