Re: [PATCH 2/2] free cmd in virNetDevVethCreate

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

 



On Fri, Oct 04, 2013 at 06:53:53PM +0800, Gao feng wrote:
> Signed-off-by: Gao feng <gaofeng@xxxxxxxxxxxxxx>
> ---
>  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 :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]