[libvirt] [PATCH 2/2] free cmd in virNetDevVethCreate
Daniel P. Berrange
berrange at redhat.com
Fri Oct 4 11:04:21 UTC 2013
On Fri, Oct 04, 2013 at 06:53:53PM +0800, Gao feng wrote:
> Signed-off-by: Gao feng <gaofeng at cn.fujitsu.com>
> ---
> src/util/virnetdevveth.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c
> index 1085217..2d727f1 100644
> --- a/src/util/virnetdevveth.c
> +++ b/src/util/virnetdevveth.c
> @@ -110,6 +110,7 @@ int virNetDevVethCreate(char** veth1, char** veth2)
> char *veth1auto = NULL;
> char *veth2auto = NULL;
> int vethNum = 0;
> + virCommandPtr cmd = NULL;
> size_t i;
>
> /*
> @@ -139,7 +140,7 @@ int virNetDevVethCreate(char** veth1, char** veth2)
> vethNum = veth2num + 1;
> }
>
> - virCommandPtr cmd = virCommandNew("ip");
> + cmd = virCommandNew("ip");
> virCommandAddArgList(cmd, "link", "add",
> *veth1 ? *veth1 : veth1auto,
> "type", "veth", "peer", "name",
> @@ -169,6 +170,7 @@ int virNetDevVethCreate(char** veth1, char** veth2)
> status);
> VIR_FREE(veth1auto);
> VIR_FREE(veth2auto);
> + virCommandFree(cmd);
> }
This needs to set cmd = NULL, to avoid double-free if the loop
terminates.
>
> virReportError(VIR_ERR_INTERNAL_ERROR,
> @@ -176,6 +178,7 @@ int virNetDevVethCreate(char** veth1, char** veth2)
> MAX_VETH_RETRIES);
>
> cleanup:
> + virCommandFree(cmd);
> VIR_FREE(veth1auto);
> VIR_FREE(veth2auto);
> return ret;
ACK, I'll push with the mentioned fix.
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
More information about the libvir-list
mailing list