diff --git a/Cython/Utility/Optimize.c b/Cython/Utility/Optimize.c
index 8ab960e8963e25ee166e246f452860f9c0c85711..89791b57f6880c978460458b82b96323a2d75014 100644
--- a/Cython/Utility/Optimize.c
+++ b/Cython/Utility/Optimize.c
@@ -321,6 +321,7 @@ static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict,
     }
 #endif
     *p_is_dict = 0;
+    *p_orig_length = 0;
     if (method_name) {
         dict = PyObject_CallMethodObjArgs(dict, method_name, NULL);
         if (!dict)