Re: [PATCH] kvm tool: Make kvm structure to carry name copy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Feb 04, 2012 at 04:20:05PM +0400, Cyrill Gorcunov wrote:
> On Sat, Feb 04, 2012 at 02:15:36PM +0200, Pekka Enberg wrote:
> > On Fri, 3 Feb 2012, Cyrill Gorcunov wrote:
> > >If guest name is used (which is default case) the kvm might end
> > >up carrying the pointer to name which is allocated on stack.
> > >
> > >kvm_cmd_run_init
> > > (on stack) default_name
> > > kvm__init(..., default_name)
> > >   kvm->name = default_name
> > >
> > >So I think better to allow kvm to carry own copy
> > >of guest name. 64 symbols should be more than enough.
> > >
> > >Signed-off-by: Cyrill Gorcunov <gorcunov@xxxxxxxxx>
> > >---
> > >
> > >I hope I didn't miss anything?
> > 
> > Can't we just use strdup()?
> > 
> 
> Yeah, I think this will be even better, I'll update.
> 

Something like below I think.

	Cyrill
---
Subject: [PATCH] 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>
---

 tools/kvm/kvm.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Index: linux-2.6.git/tools/kvm/kvm.c
===================================================================
--- linux-2.6.git.orig/tools/kvm/kvm.c
+++ linux-2.6.git/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((void *)kvm->name);
 	free(kvm);
 
 	return 0;
@@ -377,6 +378,12 @@ struct kvm *kvm__init(const char *kvm_de
 		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_de
 
 	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;
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux