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

Re: [libvirt] [PATCH] Cleanup virBuffer usage in qemdBuildCommandLine



On Fri, Nov 06, 2009 at 10:49:00AM +0000, Matthew Booth wrote:
> Dan Berrangé pointed out that using virBufferError() is preferred to checking
> virBufferContentAndReset() for NULL return. Also, this allows ADD_ARG_LIT to be
> replaced with ADD_ARG, skipping an intermediate variable.
> 
> * src/qemu_qemu_conf.c: Cleanup usage of virBuffer in qemudBuildCommandLine
> ---
>  src/qemu/qemu_conf.c |   15 ++++-----------
>  1 files changed, 4 insertions(+), 11 deletions(-)
> 
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index f010f4a..4a278e3 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -2182,7 +2182,6 @@ int qemudBuildCommandLine(virConnectPtr conn,
>  
>      for (i = 0 ; i < def->nchannels ; i++) {
>          virBuffer buf = VIR_BUFFER_INITIALIZER;
> -        const char *argStr;
>          char id[16];
>  
>          virDomainChrDefPtr channel = def->channels[i];
> @@ -2199,24 +2198,18 @@ int qemudBuildCommandLine(virConnectPtr conn,
>              }
>  
>              qemudBuildCommandLineChrDevChardevStr(channel, id, &buf);
> -            argStr = virBufferContentAndReset(&buf);
> -            if (argStr == NULL)
> +            if (virBufferError(&buf))
>                  goto error;
>  
>              ADD_ARG_LIT("-chardev");
> -            ADD_ARG_LIT(argStr);
> -
> -            VIR_FREE(argStr);
> +            ADD_ARG(virBufferContentAndReset(&buf));
>  
>              qemudBuildCommandLineChrDevTargetStr(channel, id, &buf);
> -            argStr = virBufferContentAndReset(&buf);
> -            if (argStr == NULL)
> +            if (virBufferError(&buf))
>                  goto error;
>  
>              ADD_ARG_LIT("-net");
> -            ADD_ARG_LIT(argStr);
> -
> -            VIR_FREE(argStr);
> +            ADD_ARG(virBufferContentAndReset(&buf));
>          }
>      }
>  

  Okay as ADD_ARG'ed strings are freed after use, looks fine,

   pushed, thanks !

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/


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