diff options
| author | Stefan Behnel <stefan_ml@behnel.de> | 2020-04-13 07:37:52 +0200 |
|---|---|---|
| committer | Stefan Behnel <stefan_ml@behnel.de> | 2020-04-13 07:44:21 +0200 |
| commit | acd3fdcb93261d3ce245b6359c6b1684f6ac2782 (patch) | |
| tree | 57816f8de46e6d78c5ea600674471cc9187288fc | |
| parent | bf61b1c5871346d38134eabd07405cafee497fa2 (diff) | |
| download | cython-acd3fdcb93261d3ce245b6359c6b1684f6ac2782.tar.gz | |
Fix a reference leak when PyList_Append() fails.
| -rw-r--r-- | Cython/Utility/CythonFunction.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Cython/Utility/CythonFunction.c b/Cython/Utility/CythonFunction.c index 740eaaaad..25114d6bc 100644 --- a/Cython/Utility/CythonFunction.c +++ b/Cython/Utility/CythonFunction.c @@ -972,14 +972,15 @@ __pyx_FusedFunction_getitem(__pyx_FusedFunctionObject *self, PyObject *idx) if (PyTuple_Check(idx)) { PyObject *list = PyList_New(0); Py_ssize_t n = PyTuple_GET_SIZE(idx); - PyObject *string = NULL; PyObject *sep = NULL; int i; - if (!list) + if (unlikely(!list)) return NULL; for (i = 0; i < n; i++) { + int ret; + PyObject *string; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS PyObject *item = PyTuple_GET_ITEM(idx, i); #else @@ -989,14 +990,14 @@ __pyx_FusedFunction_getitem(__pyx_FusedFunctionObject *self, PyObject *idx) #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) Py_DECREF(item); #endif - if (!string || PyList_Append(list, string) < 0) - goto __pyx_err; - + if (unlikely(!string)) goto __pyx_err; + ret = PyList_Append(list, string); Py_DECREF(string); + if (unlikely(ret < 0)) goto __pyx_err; } sep = PyUnicode_FromString("|"); - if (sep) + if (likely(sep)) signature = PyUnicode_Join(sep, list); __pyx_err: ; |
