mirror of
https://github.com/python/cpython
synced 2026-09-29 10:50:29 +03:00
Issue #20437: Fixed 22 potential bugs when deleting objects references.
This commit is contained in:
commit
dfe98a102e
15 changed files with 34 additions and 63 deletions
|
|
@ -159,10 +159,8 @@ _DictRemover_call(PyObject *myself, 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;
|
||||
|
|
@ -2934,10 +2932,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)) {
|
||||
|
|
@ -2980,10 +2976,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)
|
||||
|
|
|
|||
|
|
@ -229,8 +229,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;
|
||||
}
|
||||
|
|
@ -447,8 +446,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
|
|||
self->locked = 1;
|
||||
self->reset = 0;
|
||||
|
||||
Py_XDECREF(self->next_row);
|
||||
self->next_row = NULL;
|
||||
Py_CLEAR(self->next_row);
|
||||
|
||||
if (multiple) {
|
||||
/* executemany() */
|
||||
|
|
@ -864,8 +862,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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -780,8 +780,7 @@ typedef struct {
|
|||
static void
|
||||
path_cleanup(path_t *path) {
|
||||
if (path->cleanup) {
|
||||
Py_DECREF(path->cleanup);
|
||||
path->cleanup = NULL;
|
||||
Py_CLEAR(path->cleanup);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -317,8 +317,7 @@ call_with_frame(PyCodeObject *c, PyObject* func, PyObject* args,
|
|||
}
|
||||
else {
|
||||
if (trace_frame(tstate, f, PyTrace_RETURN, res) < 0) {
|
||||
Py_XDECREF(res);
|
||||
res = NULL;
|
||||
Py_CLEAR(res);
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -281,8 +281,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;
|
||||
|
|
@ -885,7 +884,7 @@ on_completion_display_matches_hook(char **matches,
|
|||
(r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
|
||||
goto error;
|
||||
}
|
||||
Py_XDECREF(r); r=NULL;
|
||||
Py_CLEAR(r);
|
||||
|
||||
if (0) {
|
||||
error:
|
||||
|
|
|
|||
|
|
@ -66,8 +66,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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1305,12 +1305,9 @@ finisignal(void)
|
|||
Py_XDECREF(func);
|
||||
}
|
||||
|
||||
Py_XDECREF(IntHandler);
|
||||
IntHandler = NULL;
|
||||
Py_XDECREF(DefaultHandler);
|
||||
DefaultHandler = NULL;
|
||||
Py_XDECREF(IgnoreHandler);
|
||||
IgnoreHandler = NULL;
|
||||
Py_CLEAR(IntHandler);
|
||||
Py_CLEAR(DefaultHandler);
|
||||
Py_CLEAR(IgnoreHandler);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -197,8 +197,7 @@ syslog_closelog(PyObject *self, PyObject *unused)
|
|||
{
|
||||
if (S_log_open) {
|
||||
closelog();
|
||||
Py_XDECREF(S_ident_o);
|
||||
S_ident_o = NULL;
|
||||
Py_CLEAR(S_ident_o);
|
||||
S_log_open = 0;
|
||||
}
|
||||
Py_INCREF(Py_None);
|
||||
|
|
|
|||
|
|
@ -463,8 +463,7 @@ zlib_compressobj_impl(PyModuleDef *module, int level, int method, int wbits, int
|
|||
}
|
||||
|
||||
error:
|
||||
Py_XDECREF(self);
|
||||
self = NULL;
|
||||
Py_CLEAR(self);
|
||||
success:
|
||||
return (PyObject*)self;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue