diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2021-04-30 17:26:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-30 17:26:45 +0100 |
commit | e374a40afa09be728b01653a06c9febfad9c9c50 (patch) | |
tree | a34aa1552de02d9349feb3cb062c534063cb5372 /Objects/moduleobject.c | |
parent | 7dcf0f6db38b7ab6918608542d3a0c6da0a286af (diff) | |
download | cpython-git-e374a40afa09be728b01653a06c9febfad9c9c50.tar.gz |
bpo-43901: Fix refleaks in test_module (GH-25754)
Diffstat (limited to 'Objects/moduleobject.c')
-rw-r--r-- | Objects/moduleobject.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 04346f7ad1..b69e5cedbb 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -845,6 +845,7 @@ module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored)) if ((dict == NULL) || !PyDict_Check(dict)) { PyErr_Format(PyExc_TypeError, "<module>.__dict__ is not a dictionary"); + Py_XDECREF(dict); return NULL; } @@ -876,25 +877,31 @@ module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored)) static int module_set_annotations(PyModuleObject *m, PyObject *value, void *Py_UNUSED(ignored)) { + int ret = -1; PyObject *dict = _PyObject_GetAttrId((PyObject *)m, &PyId___dict__); if ((dict == NULL) || !PyDict_Check(dict)) { PyErr_Format(PyExc_TypeError, "<module>.__dict__ is not a dictionary"); - return -1; + goto exit; } if (value != NULL) { /* set */ - return _PyDict_SetItemId(dict, &PyId___annotations__, value); + ret = _PyDict_SetItemId(dict, &PyId___annotations__, value); + goto exit; } /* delete */ if (!_PyDict_ContainsId(dict, &PyId___annotations__)) { PyErr_Format(PyExc_AttributeError, "__annotations__"); - return -1; + goto exit; } - return _PyDict_DelItemId(dict, &PyId___annotations__); + ret = _PyDict_DelItemId(dict, &PyId___annotations__); + +exit: + Py_XDECREF(dict); + return ret; } |