tools/xenstore: Correct use of va_end() after va_copy()
PATCH 1/1 tools/xenstore: Correct use of va_end() after va_copy()
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.
---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
--- tools/xenstore/talloc.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/xenstore/talloc.c +6 -0
@@ -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;
Signature · 1 line
1.7.10.4
Quoted 7 lines · Andrew Cooper
C requires that every use of
va_copy()is matched with ava_end()call.This is especially important for
x86_64as va_{start,copy}() may need to allocate memory to generate ava_listcontaining parameters which were previously in registers.Signed-off-by Andrew Cooper <[email protected]>
This is a candidate for backport.
Quoted 50 lines
---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>--- tools/xenstore/talloc.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/xenstore/talloc.c +6
-0@@ -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;Signature · 1 line
1.7.10.4
Quoted 7 lines · Andrew Cooper
C requires that every use of
va_copy()is matched with ava_end()call.This is especially important for
x86_64as va_{start,copy}() may need to allocate memory to generate ava_listcontaining parameters which were previously in registers.Signed-off-by Andrew Cooper <[email protected]>
Quoted 50 lines
---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>--- tools/xenstore/talloc.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/xenstore/talloc.c +6
-0@@ -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;Signature · 1 line
1.7.10.4
Ian Campbell
AppliedQuoted 11 lines · Wei Liu
Quoted 8 lines · Andrew Cooper
C requires that every use of
va_copy()is matched with ava_end()call.This is especially important for
x86_64as va_{start,copy}() may need to
allocate memory to generate ava_listcontaining parameters which were previously in registers.Signed-off-by Andrew Cooper <[email protected]>Release-acked-by Wei Liu <[email protected]>
Applied, thanks.