tools: acrnctl: Free vmmngr list after vm ops done

vmmngr_struct entry is allocated in get_vm_list. we should free it after vm ops done.

Signed-off-by: Kaige Fu <kaige.fu@intel.com>
Reviewed-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
Reviewed-by: Yan, Like <like.yan@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Kaige Fu 2018-05-31 10:01:35 +08:00 committed by lijinxia
parent 2da5e7c16a
commit 3000edc6ad
3 changed files with 22 additions and 7 deletions

View File

@ -93,6 +93,17 @@ void get_vm_list(void)
}
}
void put_vm_list(void)
{
struct vmmngr_struct *s;
while (!LIST_EMPTY(&vmmngr_head)) {
s = LIST_FIRST(&vmmngr_head);
LIST_REMOVE(s, list);
free(s);
}
}
/* helper functions */
int shell_cmd(const char *cmd, char *outbuf, int len)
{

View File

@ -45,7 +45,6 @@ struct acrnctl_cmd {
/* command: list */
static int acrnctl_do_list(int argc, char *argv[])
{
get_vm_list();
return list_vm();
}
@ -265,7 +264,6 @@ static int acrnctl_do_add(int argc, char *argv[])
snprintf(cmd, sizeof(cmd), "mkdir -p %s/add", ACRNCTL_OPT_ROOT);
system(cmd);
get_vm_list();
s = vmmngr_find(vmname);
if (s) {
printf("%s(%s) already exist, can't add %s%s\n",
@ -313,7 +311,6 @@ static int acrnctl_do_stop(int argc, char *argv[])
struct vmmngr_struct *s;
int i;
get_vm_list();
for (i = 1; i < argc; i++) {
s = vmmngr_find(argv[i]);
if (!s) {
@ -338,7 +335,6 @@ static int acrnctl_do_del(int argc, char *argv[])
int i;
char cmd[128];
get_vm_list();
for (i = 1; i < argc; i++) {
s = vmmngr_find(argv[i]);
if (!s) {
@ -365,7 +361,6 @@ static int acrnctl_do_start(int argc, char *argv[])
{
struct vmmngr_struct *s;
get_vm_list();
s = vmmngr_find(argv[1]);
if (!s) {
printf("can't find %s\n", argv[1]);
@ -451,7 +446,7 @@ static void usage(void)
int main(int argc, char *argv[])
{
int i;
int i, err;
if (argc == 1 || !strcmp(argv[1], "help")) {
usage();
@ -471,7 +466,11 @@ int main(int argc, char *argv[])
if (acmds[i].valid_args(&acmds[i], argc - 1, &argv[1])) {
return -1;
} else {
return acmds[i].func(argc - 1, &argv[1]);
get_vm_list();
err = acmds[i].func(argc - 1, &argv[1]);
put_vm_list();
return err;
}
}

View File

@ -34,6 +34,11 @@ static const char *state_str[] = {
*/
void get_vm_list(void);
/**
* @brief free all vmmngr_struct allocated by get_vm_list
*/
void put_vm_list(void);
/**
* @brief search vm indentified by vm from vmmngr_head
*