diff --git a/Objects/abstract.c b/Objects/abstract.c index c6c957b302b..c1671253ec8 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -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; } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index f0a908386fe..7984454856f 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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; } diff --git a/Python/getargs.c b/Python/getargs.c index cd80eda0e23..43656eb2aae 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -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; } diff --git a/Python/modsupport.c b/Python/modsupport.c index bdaf8b22c58..aabee8fa59d 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -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; }