Commit-ID: c929ceec678765a9a7c6e769e9a99ba79ac9fcd2 Gitweb: http://git.kernel.org/tip/c929ceec678765a9a7c6e769e9a99ba79ac9fcd2 Author: Cyrill Gorcunov <gorcunov@xxxxxxxxxx> AuthorDate: Sat, 4 Feb 2012 17:08:04 +0400 Committer: Pekka Enberg <penberg@xxxxxxxxxx> CommitDate: Sat, 4 Feb 2012 17:36:10 +0200 kvm tool: Make kvm structure to carry name copy If default guest name is used (which is the default case) the kvm might end up carrying the pointer to a name which is allocated on stack. kvm_cmd_run_init (on stack) default_name kvm__init(..., default_name) kvm->name = default_name So make it to carry a copy of name. Signed-off-by: Cyrill Gorcunov <gorcunov@xxxxxxxxx> Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx> --- tools/kvm/kvm.c | 9 +++++++-- tools/kvm/powerpc/include/kvm/kvm-arch.h | 2 +- tools/kvm/x86/include/kvm/kvm-arch.h | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index 04bb54e..74e37ae 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -254,6 +254,7 @@ int kvm__exit(struct kvm *kvm) kvm__arch_delete_ram(kvm); kvm_ipc__stop(); kvm__remove_socket(kvm->name); + free(kvm->name); free(kvm); return 0; @@ -377,6 +378,12 @@ struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 ram_s goto cleanup; } + kvm->name = strdup(name); + if (!kvm->name) { + ret = -ENOMEM; + goto cleanup; + } + if (kvm__check_extensions(kvm)) { pr_err("A required KVM extention is not supported by OS"); ret = -ENOSYS; @@ -384,8 +391,6 @@ struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 ram_s kvm__arch_init(kvm, hugetlbfs_path, ram_size); - kvm->name = name; - kvm_ipc__start(kvm__create_socket(kvm)); kvm_ipc__register_handler(KVM_IPC_PID, kvm__pid); return kvm; diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h b/tools/kvm/powerpc/include/kvm/kvm-arch.h index 6dd7082..c7620b2 100644 --- a/tools/kvm/powerpc/include/kvm/kvm-arch.h +++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h @@ -69,7 +69,7 @@ struct kvm { unsigned long fdt_gra; unsigned long initrd_gra; unsigned long initrd_size; - const char *name; + char *name; int vm_state; struct icp_state *icp; struct spapr_phb *phb; diff --git a/tools/kvm/x86/include/kvm/kvm-arch.h b/tools/kvm/x86/include/kvm/kvm-arch.h index ba04561..31c0fb8 100644 --- a/tools/kvm/x86/include/kvm/kvm-arch.h +++ b/tools/kvm/x86/include/kvm/kvm-arch.h @@ -48,7 +48,7 @@ struct kvm { struct disk_image **disks; int nr_disks; - const char *name; + char *name; int vm_state; }; -- To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html