summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-02-09 11:14:04 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-02-09 11:14:04 (GMT)
commit98a9722e4a82b5f7dc0411233bbec892a02c7667 (patch)
tree51179bb7d80e822a18d0ccbb41fde7198f424813 /Modules
parent2cfae9b03f706e0d6889dfecc21f87419d926b00 (diff)
downloadcpython-98a9722e4a82b5f7dc0411233bbec892a02c7667.zip
cpython-98a9722e4a82b5f7dc0411233bbec892a02c7667.tar.gz
cpython-98a9722e4a82b5f7dc0411233bbec892a02c7667.tar.bz2
Issue #20437: Fixed 43 potential bugs when deleting objects references.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_bsddb.c21
-rw-r--r--Modules/_ctypes/_ctypes.c18
-rw-r--r--Modules/_elementtree.c8
-rw-r--r--Modules/_sqlite/connection.c3
-rw-r--r--Modules/_sqlite/cursor.c9
-rw-r--r--Modules/cPickle.c3
-rw-r--r--Modules/cdmodule.c18
-rw-r--r--Modules/flmodule.c12
-rw-r--r--Modules/readline.c3
-rw-r--r--Modules/selectmodule.c3
-rw-r--r--Modules/svmodule.c3
11 files changed, 35 insertions, 66 deletions
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index dad1dcd..203bba2 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -949,8 +949,7 @@ newDBObject(DBEnvObject* arg, int flags)
* DBTxns and closing any open DBs first. */
if (makeDBError(err)) {
if (self->myenvobj) {
- Py_DECREF(self->myenvobj);
- self->myenvobj = NULL;
+ Py_CLEAR(self->myenvobj);
}
Py_DECREF(self);
self = NULL;
@@ -982,20 +981,16 @@ DB_dealloc(DBObject* self)
PyObject_ClearWeakRefs((PyObject *) self);
}
if (self->myenvobj) {
- Py_DECREF(self->myenvobj);
- self->myenvobj = NULL;
+ Py_CLEAR(self->myenvobj);
}
if (self->associateCallback != NULL) {
- Py_DECREF(self->associateCallback);
- self->associateCallback = NULL;
+ Py_CLEAR(self->associateCallback);
}
if (self->btCompareCallback != NULL) {
- Py_DECREF(self->btCompareCallback);
- self->btCompareCallback = NULL;
+ Py_CLEAR(self->btCompareCallback);
}
if (self->dupCompareCallback != NULL) {
- Py_DECREF(self->dupCompareCallback);
- self->dupCompareCallback = NULL;
+ Py_CLEAR(self->dupCompareCallback);
}
Py_DECREF(self->private_obj);
PyObject_Del(self);
@@ -1160,8 +1155,7 @@ DBEnv_dealloc(DBEnvObject* self)
PyErr_Clear();
}
- Py_XDECREF(self->event_notifyCallback);
- self->event_notifyCallback = NULL;
+ Py_CLEAR(self->event_notifyCallback);
if (self->in_weakreflist != NULL) {
PyObject_ClearWeakRefs((PyObject *) self);
@@ -1640,8 +1634,7 @@ DB_associate(DBObject* self, PyObject* args, PyObject* kwargs)
MYDB_END_ALLOW_THREADS;
if (err) {
- Py_XDECREF(secondaryDB->associateCallback);
- secondaryDB->associateCallback = NULL;
+ Py_CLEAR(secondaryDB->associateCallback);
secondaryDB->primaryDBType = 0;
}
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 599d90a..8ba6443 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -194,10 +194,8 @@ _DictRemover_call(PyObject *_self, PyObject *args, PyObject *kw)
if (-1 == PyDict_DelItem(self->dict, self->key))
/* XXX Error context */
PyErr_WriteUnraisable(Py_None);
- Py_DECREF(self->key);
- self->key = NULL;
- Py_DECREF(self->dict);
- self->dict = NULL;
+ Py_CLEAR(self->key);
+ Py_CLEAR(self->dict);
}
Py_INCREF(Py_None);
return Py_None;
@@ -3040,10 +3038,8 @@ static int
PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob)
{
if (ob == NULL) {
- Py_XDECREF(self->restype);
- self->restype = NULL;
- Py_XDECREF(self->checker);
- self->checker = NULL;
+ Py_CLEAR(self->restype);
+ Py_CLEAR(self->checker);
return 0;
}
if (ob != Py_None && !PyType_stgdict(ob) && !PyCallable_Check(ob)) {
@@ -3086,10 +3082,8 @@ PyCFuncPtr_set_argtypes(PyCFuncPtrObject *self, PyObject *ob)
PyObject *converters;
if (ob == NULL || ob == Py_None) {
- Py_XDECREF(self->converters);
- self->converters = NULL;
- Py_XDECREF(self->argtypes);
- self->argtypes = NULL;
+ Py_CLEAR(self->converters);
+ Py_CLEAR(self->argtypes);
} else {
converters = converters_from_argtypes(ob);
if (!converters)
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index ae07ca3..3e9f9df 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -2739,10 +2739,10 @@ xmlparser_setevents(XMLParserObject* self, PyObject* args)
target->events = events;
/* clear out existing events */
- Py_XDECREF(target->start_event_obj); target->start_event_obj = NULL;
- Py_XDECREF(target->end_event_obj); target->end_event_obj = NULL;
- Py_XDECREF(target->start_ns_event_obj); target->start_ns_event_obj = NULL;
- Py_XDECREF(target->end_ns_event_obj); target->end_ns_event_obj = NULL;
+ Py_CLEAR(target->start_event_obj);
+ Py_CLEAR(target->end_event_obj);
+ Py_CLEAR(target->start_ns_event_obj);
+ Py_CLEAR(target->end_ns_event_obj);
if (event_set == Py_None) {
/* default is "end" only */
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 59966dad..7a8a5a1 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -369,8 +369,7 @@ PyObject* pysqlite_connection_close(pysqlite_Connection* self, PyObject* args)
if (self->apsw_connection) {
ret = PyObject_CallMethod(self->apsw_connection, "close", "");
Py_XDECREF(ret);
- Py_XDECREF(self->apsw_connection);
- self->apsw_connection = NULL;
+ Py_CLEAR(self->apsw_connection);
self->db = NULL;
} else {
Py_BEGIN_ALLOW_THREADS
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index f06f92c..3b84484 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -231,8 +231,7 @@ int pysqlite_build_row_cast_map(pysqlite_Cursor* self)
if (converter != Py_None) {
Py_DECREF(converter);
}
- Py_XDECREF(self->row_cast_map);
- self->row_cast_map = NULL;
+ Py_CLEAR(self->row_cast_map);
return -1;
}
@@ -468,8 +467,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
allow_8bit_chars = ((self->connection->text_factory != (PyObject*)&PyUnicode_Type) &&
(self->connection->text_factory != pysqlite_OptimizedUnicode));
- Py_XDECREF(self->next_row);
- self->next_row = NULL;
+ Py_CLEAR(self->next_row);
if (multiple) {
/* executemany() */
@@ -896,8 +894,7 @@ PyObject* pysqlite_cursor_iternext(pysqlite_Cursor *self)
if (!self->next_row) {
if (self->statement) {
(void)pysqlite_statement_reset(self->statement);
- Py_DECREF(self->statement);
- self->statement = NULL;
+ Py_CLEAR(self->statement);
}
return NULL;
}
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index 8145bbf..10199eb 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -324,8 +324,7 @@ Pdata_popList(Pdata *self, Py_ssize_t start)
#define FREE_ARG_TUP(self) { \
if (Py_REFCNT(self->arg) > 1) { \
- Py_DECREF(self->arg); \
- self->arg=NULL; \
+ Py_CLEAR(self->arg); \
} \
}
diff --git a/Modules/cdmodule.c b/Modules/cdmodule.c
index 8dfb769..9ee9b0b 100644
--- a/Modules/cdmodule.c
+++ b/Modules/cdmodule.c
@@ -535,10 +535,8 @@ CD_deleteparser(cdparserobject *self, PyObject *args)
/* no sense in keeping the callbacks, so remove them */
for (i = 0; i < NCALLBACKS; i++) {
- Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback);
- self->ob_cdcallbacks[i].ob_cdcallback = NULL;
- Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg);
- self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
+ Py_CLEAR(self->ob_cdcallbacks[i].ob_cdcallback);
+ Py_CLEAR(self->ob_cdcallbacks[i].ob_cdcallbackarg);
}
Py_INCREF(Py_None);
@@ -588,11 +586,9 @@ CD_removecallback(cdparserobject *self, PyObject *args)
CDremovecallback(self->ob_cdparser, (CDDATATYPES) type);
- Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback);
- self->ob_cdcallbacks[type].ob_cdcallback = NULL;
+ Py_CLEAR(self->ob_cdcallbacks[type].ob_cdcallback);
- Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg);
- self->ob_cdcallbacks[type].ob_cdcallbackarg = NULL;
+ Py_CLEAR(self->ob_cdcallbacks[type].ob_cdcallbackarg);
Py_INCREF(Py_None);
return Py_None;
@@ -668,10 +664,8 @@ cdparser_dealloc(cdparserobject *self)
int i;
for (i = 0; i < NCALLBACKS; i++) {
- Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback);
- self->ob_cdcallbacks[i].ob_cdcallback = NULL;
- Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg);
- self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL;
+ Py_CLEAR(self->ob_cdcallbacks[i].ob_cdcallback);
+ Py_CLEAR(self->ob_cdcallbacks[i].ob_cdcallbackarg);
}
CDdeleteparser(self->ob_cdparser);
PyObject_Del(self);
diff --git a/Modules/flmodule.c b/Modules/flmodule.c
index b5a78cf..0ddf600 100644
--- a/Modules/flmodule.c
+++ b/Modules/flmodule.c
@@ -97,10 +97,8 @@ forgetgeneric(genericobject *g)
{
int i, n;
- Py_XDECREF(g->ob_callback);
- g->ob_callback = NULL;
- Py_XDECREF(g->ob_callback_arg);
- g->ob_callback_arg = NULL;
+ Py_CLEAR(g->ob_callback);
+ Py_CLEAR(g->ob_callback_arg);
if (allgenerics == NULL)
return; /* No objects known yet */
n = PyList_Size(allgenerics);
@@ -132,10 +130,8 @@ releaseobjects(FL_FORM *form)
/* The object is now unreachable for
do_forms and check_forms, so
delete it from the list of known objects */
- Py_XDECREF(g->ob_callback);
- g->ob_callback = NULL;
- Py_XDECREF(g->ob_callback_arg);
- g->ob_callback_arg = NULL;
+ Py_CLEAR(g->ob_callback);
+ Py_CLEAR(g->ob_callback_arg);
PyList_SetItem(allgenerics, i, (PyObject *)NULL);
nfreeslots++;
}
diff --git a/Modules/readline.c b/Modules/readline.c
index a5d48c9..f19fa0b 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -206,8 +206,7 @@ set_hook(const char *funcname, PyObject **hook_var, PyObject *args)
if (!PyArg_ParseTuple(args, buf, &function))
return NULL;
if (function == Py_None) {
- Py_XDECREF(*hook_var);
- *hook_var = NULL;
+ Py_CLEAR(*hook_var);
}
else if (PyCallable_Check(function)) {
PyObject *tmp = *hook_var;
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 6071996..2707b05 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -71,8 +71,7 @@ reap_obj(pylist fd2obj[FD_SETSIZE + 1])
{
int i;
for (i = 0; i < FD_SETSIZE + 1 && fd2obj[i].sentinel >= 0; i++) {
- Py_XDECREF(fd2obj[i].obj);
- fd2obj[i].obj = NULL;
+ Py_CLEAR(fd2obj[i].obj);
}
fd2obj[0].sentinel = -1;
}
diff --git a/Modules/svmodule.c b/Modules/svmodule.c
index 6e419ce..1519065 100644
--- a/Modules/svmodule.c
+++ b/Modules/svmodule.c
@@ -279,8 +279,7 @@ capture_dealloc(captureobject *self)
(void)svUnlockCaptureData(self->ob_svideo->ob_svideo,
self->ob_capture);
self->ob_capture = NULL;
- Py_DECREF(self->ob_svideo);
- self->ob_svideo = NULL;
+ Py_CLEAR(self->ob_svideo);
}
PyObject_Del(self);
}