Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r2973:6e1b6c8e1d79 Date: 2017-06-04 15:06 +0200 http://bitbucket.org/cffi/cffi/changeset/6e1b6c8e1d79/
Log: Figured out a memory leak in an error case diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c --- a/c/_cffi_backend.c +++ b/c/_cffi_backend.c @@ -4137,7 +4137,10 @@ assert(x->ct_unique_key == NULL); x->ct_unique_key = key; /* the key will be freed in ctypedescr_dealloc() */ - Py_DECREF(x); /* the 'value' in unique_cache doesn't count as 1 */ + /* the 'value' in unique_cache doesn't count as 1, but don't use + Py_DECREF(x) here because it will confuse debug builds into thinking + there was an extra DECREF in total. */ + ((PyObject *)x)->ob_refcnt--; return (PyObject *)x; error: @@ -6231,6 +6234,7 @@ src = cd->c_data; itemsize = ctitem->ct_size; if (itemsize < 0) { + Py_DECREF(result); PyErr_Format(PyExc_ValueError, "'%s' points to items of unknown size", cd->c_type->ct_name); return NULL; _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit