va_end() all va_copy()ed va_lists.

This commit is contained in:
Christian Heimes 2016-09-21 11:37:27 +02:00
parent 1c56bf0bad
commit 2f2fee19ec
4 changed files with 26 additions and 7 deletions

View File

@ -2702,6 +2702,7 @@ objargs_mkstack(PyObject **small_stack, Py_ssize_t small_stack_size,
else {
stack = PyMem_Malloc(n * sizeof(stack[0]));
if (stack == NULL) {
va_end(countva);
PyErr_NoMemory();
return NULL;
}
@ -2710,6 +2711,7 @@ objargs_mkstack(PyObject **small_stack, Py_ssize_t small_stack_size,
for (i = 0; i < n; ++i) {
stack[i] = va_arg(va, PyObject *);
}
va_end(countva);
return stack;
}

View File

@ -2891,6 +2891,7 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
do
{
if ((unsigned char)*p > 127) {
va_end(vargs2);
PyErr_Format(PyExc_ValueError,
"PyUnicode_FromFormatV() expects an ASCII-encoded format "
"string, got a non-ASCII byte: 0x%02x",
@ -2911,9 +2912,11 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
f = p;
}
}
va_end(vargs2);
return _PyUnicodeWriter_Finish(&writer);
fail:
va_end(vargs2);
_PyUnicodeWriter_Dealloc(&writer);
return NULL;
}

View File

@ -141,20 +141,26 @@ int
PyArg_VaParse(PyObject *args, const char *format, va_list va)
{
va_list lva;
int retval;
va_copy(lva, va);
return vgetargs1(args, format, &lva, 0);
retval = vgetargs1(args, format, &lva, 0);
va_end(lva);
return retval;
}
int
_PyArg_VaParse_SizeT(PyObject *args, const char *format, va_list va)
{
va_list lva;
int retval;
va_copy(lva, va);
return vgetargs1(args, format, &lva, FLAG_SIZE_T);
retval = vgetargs1(args, format, &lva, FLAG_SIZE_T);
va_end(lva);
return retval;
}
@ -1405,6 +1411,7 @@ PyArg_VaParseTupleAndKeywords(PyObject *args,
va_copy(lva, va);
retval = vgetargskeywords(args, keywords, format, kwlist, &lva, 0);
va_end(lva);
return retval;
}
@ -1430,6 +1437,7 @@ _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *args,
retval = vgetargskeywords(args, keywords, format,
kwlist, &lva, FLAG_SIZE_T);
va_end(lva);
return retval;
}
@ -1534,6 +1542,7 @@ _PyArg_VaParseTupleAndKeywordsFast(PyObject *args, PyObject *keywords,
va_copy(lva, va);
retval = vgetargskeywordsfast(args, keywords, parser, &lva, 0);
va_end(lva);
return retval;
}
@ -1555,6 +1564,7 @@ _PyArg_VaParseTupleAndKeywordsFast_SizeT(PyObject *args, PyObject *keywords,
va_copy(lva, va);
retval = vgetargskeywordsfast(args, keywords, parser, &lva, FLAG_SIZE_T);
va_end(lva);
return retval;
}

View File

@ -467,8 +467,7 @@ va_build_value(const char *format, va_list va, int flags)
const char *f = format;
int n = countformat(f, '\0');
va_list lva;
va_copy(lva, va);
PyObject *retval;
if (n < 0)
return NULL;
@ -476,9 +475,14 @@ va_build_value(const char *format, va_list va, int flags)
Py_INCREF(Py_None);
return Py_None;
}
if (n == 1)
return do_mkvalue(&f, &lva, flags);
return do_mktuple(&f, &lva, '\0', n, flags);
va_copy(lva, va);
if (n == 1) {
retval = do_mkvalue(&f, &lva, flags);
} else {
retval = do_mktuple(&f, &lva, '\0', n, flags);
}
va_end(lva);
return retval;
}