]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commitdiff
tools/xenstore: Correct use of va_end() after va_copy()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 7 Aug 2015 13:51:59 +0000 (14:51 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 13 Aug 2015 09:58:43 +0000 (10:58 +0100)
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@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/xenstore/talloc.c

index 54dbd0270663dc0db80850dd7ad7e2db0a6e048c..d7edcf3a933bcf5986382be88efbf0c8c1e30651 100644 (file)
@@ -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;