summaryrefslogtreecommitdiffstats
path: root/Objects/frameobject.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-12-06 15:48:16 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-12-06 15:48:16 (GMT)
commit1a48ca8c53b80627ebf3c4215140cdc07152556d (patch)
treec22b89bcf2e70e08224ddf7677d9010bafa6cb01 /Objects/frameobject.c
parent7802a53e38399e8df647f0633f18658b7bb1be4a (diff)
downloadcpython-1a48ca8c53b80627ebf3c4215140cdc07152556d.zip
cpython-1a48ca8c53b80627ebf3c4215140cdc07152556d.tar.gz
cpython-1a48ca8c53b80627ebf3c4215140cdc07152556d.tar.bz2
Fix memory leak in dict_to_map(), SF bug [ #485152 ] memory leak in test_scope.
PyCell_Set() incremenets the reference count, so the earlier XINCREF causes a leak. Also make a number of small performance improvements to the code on the assumption that most of the time variables are not rebound across a FastToLocals() / LocalsToFast() pair. Replace uses of PyCell_Set() and PyCell_Get() with PyCell_SET() and PyCell_GET(), since the frame is guaranteed to contain cells.
Diffstat (limited to 'Objects/frameobject.c')
-rw-r--r--Objects/frameobject.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index e092ce6..cf3d73a 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -345,12 +345,11 @@ map_to_dict(PyObject *map, int nmap, PyObject *dict, PyObject **values,
{
int j;
for (j = nmap; --j >= 0; ) {
- PyObject *key = PyTuple_GetItem(map, j);
+ PyObject *key = PyTuple_GET_ITEM(map, j);
PyObject *value = values[j];
if (deref)
value = PyCell_GET(value);
if (value == NULL) {
- PyErr_Clear();
if (PyDict_DelItem(dict, key) != 0)
PyErr_Clear();
}
@@ -367,17 +366,21 @@ dict_to_map(PyObject *map, int nmap, PyObject *dict, PyObject **values,
{
int j;
for (j = nmap; --j >= 0; ) {
- PyObject *key = PyTuple_GetItem(map, j);
+ PyObject *key = PyTuple_GET_ITEM(map, j);
PyObject *value = PyDict_GetItem(dict, key);
- Py_XINCREF(value);
if (deref) {
if (value || clear) {
- if (PyCell_Set(values[j], value) < 0)
- PyErr_Clear();
+ if (PyCell_GET(values[j]) != value) {
+ if (PyCell_Set(values[j], value) < 0)
+ PyErr_Clear();
+ }
}
} else if (value != NULL || clear) {
- Py_XDECREF(values[j]);
- values[j] = value;
+ if (values[j] != value) {
+ Py_XINCREF(value);
+ Py_XDECREF(values[j]);
+ values[j] = value;
+ }
}
}
}