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

Re: [Xen-devel] [PATCH for-4.6] tools/xenstore: Correct use of va_end() after va_copy()



On Fri, Aug 07, 2015 at 02:51:59PM +0100, Andrew Cooper wrote:
> C requires that every use of va_copy() is matched with a va_end() call.
> 
> This is especially important for x86_64 as va_{start,copy}() may need to
> allocate memory to generate a va_list containing parameters which were
> previously in registers.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>

Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>

This is a candidate for backport.

> ---
> CC: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
> CC: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
> CC: Wei Liu <wei.liu2@xxxxxxxxxx>
> ---
>  tools/xenstore/talloc.c |    6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/tools/xenstore/talloc.c b/tools/xenstore/talloc.c
> index 54dbd02..d7edcf3 100644
> --- a/tools/xenstore/talloc.c
> +++ b/tools/xenstore/talloc.c
> @@ -1101,13 +1101,16 @@ char *talloc_vasprintf(const void *t, const char 
> *fmt, va_list ap)
>  
>       /* this call looks strange, but it makes it work on older solaris boxes 
> */
>       if ((len = vsnprintf(&c, 1, fmt, ap2)) < 0) {
> +             va_end(ap2);
>               return NULL;
>       }
> +     va_end(ap2);
>  
>       ret = _talloc(t, len+1);
>       if (ret) {
>               VA_COPY(ap2, ap);
>               vsnprintf(ret, len+1, fmt, ap2);
> +             va_end(ap2);
>               talloc_set_name_const(ret, ret);
>       }
>  
> @@ -1161,8 +1164,10 @@ static char *talloc_vasprintf_append(char *s, const 
> char *fmt, va_list ap)
>                * the original string. Most current callers of this 
>                * function expect it to never return NULL.
>                */
> +             va_end(ap2);
>               return s;
>       }
> +     va_end(ap2);
>  
>       s = talloc_realloc(NULL, s, char, s_len + len+1);
>       if (!s) return NULL;
> @@ -1170,6 +1175,7 @@ static char *talloc_vasprintf_append(char *s, const 
> char *fmt, va_list ap)
>       VA_COPY(ap2, ap);
>  
>       vsnprintf(s+s_len, len+1, fmt, ap2);
> +     va_end(ap2);
>       talloc_set_name_const(s, s);
>  
>       return s;
> -- 
> 1.7.10.4

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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