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

[Xen-devel] [PATCH 01 of 14] libxl: fix memory management in "xl network-attach"



# HG changeset patch
# User David Scott <dave.scott@xxxxxxxxxxxxx>
# Date 1301507668 -3600
# Node ID 746e49e61dbc79797d1206a96e5b65651874b1bf
# Parent  a65612bcbb921e98a8843157bf365e4ab16e8144
libxl: fix memory management in "xl network-attach"

The libxl_device_nic struct has strings which are initially strdup()ed and then 
free()ed in libxl_device_nic_destroy(). In the "network-attach" parser we need 
to free() the existing string and strdup((*argv) + N), rather than just copying 
the pointer.

Signed-off-by: David Scott <dave.scott@xxxxxxxxxxxxx>
Acked-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r a65612bcbb92 -r 746e49e61dbc tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Fri Mar 25 09:03:17 2011 +0000
+++ b/tools/libxl/xl_cmdimpl.c  Wed Mar 30 18:54:28 2011 +0100
@@ -4277,12 +4277,14 @@ int main_networkattach(int argc, char **
                 nic.mac[i] = val;
             }
         } else if (!strncmp("bridge=", *argv, 7)) {
-            nic.bridge = (*argv) + 7;
+            free(nic.bridge);
+            nic.bridge = strdup((*argv) + 7);
         } else if (!strncmp("ip=", *argv, 3)) {
             free(nic.ip);
             nic.ip = strdup((*argv) + 3);
         } else if (!strncmp("script=", *argv, 6)) {
-            nic.script = (*argv) + 6;
+            free(nic.script);
+            nic.script = strdup((*argv) + 6);
         } else if (!strncmp("backend=", *argv, 8)) {
             if(libxl_name_to_domid(&ctx, ((*argv) + 8), &val)) {
                 fprintf(stderr, "Specified backend domain does not exist, 
defaulting to Dom0\n");
@@ -4290,9 +4292,11 @@ int main_networkattach(int argc, char **
             }
             nic.backend_domid = val;
         } else if (!strncmp("vifname=", *argv, 8)) {
-            nic.ifname = (*argv) + 8;
+            free(nic.ifname);
+            nic.ifname = strdup((*argv) + 8);
         } else if (!strncmp("model=", *argv, 6)) {
-            nic.model = (*argv) + 6;
+            free(nic.model);
+            nic.model = strdup((*argv) + 6);
         } else if (!strncmp("rate=", *argv, 5)) {
         } else if (!strncmp("accel=", *argv, 6)) {
         } else {

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.