summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-09-01 07:02:44 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-09-01 07:02:44 (GMT)
commit75ccea3777f77f001102493170490874166eb3b2 (patch)
tree31c6cc1fc38e8928475d7dd3a04fe3e3d0b0a33c
parent410eb84a5d4e582491701d63d154959c05a457f4 (diff)
downloadcpython-75ccea3777f77f001102493170490874166eb3b2.zip
cpython-75ccea3777f77f001102493170490874166eb3b2.tar.gz
cpython-75ccea3777f77f001102493170490874166eb3b2.tar.bz2
SF patch #1020188: Use Py_CLEAR where necessary to avoid crashes
(Contributed by Dima Dorfman)
-rw-r--r--Include/object.h2
-rw-r--r--Modules/itertoolsmodule.c3
-rw-r--r--Objects/enumobject.c5
-rw-r--r--Objects/genobject.c3
-rw-r--r--Objects/iterobject.c12
5 files changed, 8 insertions, 17 deletions
diff --git a/Include/object.h b/Include/object.h
index 5db4dac..258b074 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -623,7 +623,7 @@ PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
#define Py_CLEAR(op) \
do { \
if (op) { \
- PyObject *tmp = (op); \
+ PyObject *tmp = (PyObject *)(op); \
(op) = NULL; \
Py_DECREF(tmp); \
} \
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 21659fb..bf2c493 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -250,8 +250,7 @@ _grouper_next(_grouperobject *igo)
r = gbo->currvalue;
gbo->currvalue = NULL;
- Py_DECREF(gbo->currkey);
- gbo->currkey = NULL;
+ Py_CLEAR(gbo->currkey);
return r;
}
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index ebe7e7c..aac88db 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -230,10 +230,7 @@ reversed_next(reversedobject *ro)
PyErr_Clear();
}
ro->index = -1;
- if (ro->seq != NULL) {
- Py_DECREF(ro->seq);
- ro->seq = NULL;
- }
+ Py_CLEAR(ro->seq);
return NULL;
}
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 66a5106..174c697 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -51,8 +51,7 @@ gen_iternext(PyGenObject *gen)
* may keep a chain of frames alive or it could create a reference
* cycle. */
assert(f->f_back != NULL);
- Py_DECREF(f->f_back);
- f->f_back = NULL;
+ Py_CLEAR(f->f_back);
/* If the generator just returned (as opposed to yielding), signal
* that the generator is exhausted. */
diff --git a/Objects/iterobject.c b/Objects/iterobject.c
index 25e4e11..b414cc2 100644
--- a/Objects/iterobject.c
+++ b/Objects/iterobject.c
@@ -192,18 +192,14 @@ calliter_iternext(calliterobject *it)
return result; /* Common case, fast path */
Py_DECREF(result);
if (ok > 0) {
- Py_DECREF(it->it_callable);
- it->it_callable = NULL;
- Py_DECREF(it->it_sentinel);
- it->it_sentinel = NULL;
+ Py_CLEAR(it->it_callable);
+ Py_CLEAR(it->it_sentinel);
}
}
else if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
PyErr_Clear();
- Py_DECREF(it->it_callable);
- it->it_callable = NULL;
- Py_DECREF(it->it_sentinel);
- it->it_sentinel = NULL;
+ Py_CLEAR(it->it_callable);
+ Py_CLEAR(it->it_sentinel);
}
}
return NULL;