]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-24076: Fix reference in sum() introduced by GH-28469 (GH-28493)
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Tue, 21 Sep 2021 17:38:57 +0000 (18:38 +0100)
committerGitHub <noreply@github.com>
Tue, 21 Sep 2021 17:38:57 +0000 (18:38 +0100)
Python/bltinmodule.c

index 38bdfb2766f3df0e362e560dc3d5111ad84b848f..d0d31805b3018de697f17936e1a3fbf6a3714b66 100644 (file)
@@ -2484,7 +2484,8 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
                 /* Single digits are common, fast, and cannot overflow on unpacking. */
                 switch (Py_SIZE(item)) {
                     case -1: b = -(sdigit) ((PyLongObject*)item)->ob_digit[0]; break;
-                    case  0: continue;
+                    // Note: the continue goes to the top of the "while" loop that iterates over the elements
+                    case  0: Py_DECREF(item); continue; 
                     case  1: b = ((PyLongObject*)item)->ob_digit[0]; break;
                     default: b = PyLong_AsLongAndOverflow(item, &overflow); break;
                 }