From: David Scott Date: Thu, 31 Mar 2011 18:19:16 +0000 (+0100) Subject: libxl: fix memory management in "xl network-attach" X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=0021f2b8d6bad056f3b9d0c3afef25fbf5a23f2d;p=people%2Fliuw%2Flibxenctrl-split%2Fxen.git 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 Acked-by: Stefano Stabellini Acked-by: Ian Campbell Committed-by: Ian Jackson --- diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 8a927b8836..3cf3ee24a6 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -4277,12 +4277,14 @@ int main_networkattach(int argc, char **argv) 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 **argv) } 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 {