Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 505ff75

Browse files
Issue #20437: Fixed 21 potential bugs when deleting objects references.
1 parent e9c3147 commit 505ff75

16 files changed

Lines changed: 34 additions & 63 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ What's New in Python 3.3.4 release candidate 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #20437: Fixed 21 potential bugs when deleting objects references.
14+
1315
- Issue #20538: UTF-7 incremental decoder produced inconsistant string when
1416
input was truncated in BASE64 section.
1517

Modules/_ctypes/_ctypes.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,8 @@ _DictRemover_call(PyObject *myself, PyObject *args, PyObject *kw)
159159
if (-1 == PyDict_DelItem(self->dict, self->key))
160160
/* XXX Error context */
161161
PyErr_WriteUnraisable(Py_None);
162-
Py_DECREF(self->key);
163-
self->key = NULL;
164-
Py_DECREF(self->dict);
165-
self->dict = NULL;
162+
Py_CLEAR(self->key);
163+
Py_CLEAR(self->dict);
166164
}
167165
Py_INCREF(Py_None);
168166
return Py_None;
@@ -2930,10 +2928,8 @@ static int
29302928
PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob)
29312929
{
29322930
if (ob == NULL) {
2933-
Py_XDECREF(self->restype);
2934-
self->restype = NULL;
2935-
Py_XDECREF(self->checker);
2936-
self->checker = NULL;
2931+
Py_CLEAR(self->restype);
2932+
Py_CLEAR(self->checker);
29372933
return 0;
29382934
}
29392935
if (ob != Py_None && !PyType_stgdict(ob) && !PyCallable_Check(ob)) {
@@ -2976,10 +2972,8 @@ PyCFuncPtr_set_argtypes(PyCFuncPtrObject *self, PyObject *ob)
29762972
PyObject *converters;
29772973

29782974
if (ob == NULL || ob == Py_None) {
2979-
Py_XDECREF(self->converters);
2980-
self->converters = NULL;
2981-
Py_XDECREF(self->argtypes);
2982-
self->argtypes = NULL;
2975+
Py_CLEAR(self->converters);
2976+
Py_CLEAR(self->argtypes);
29832977
} else {
29842978
converters = converters_from_argtypes(ob);
29852979
if (!converters)

Modules/_sqlite/cursor.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ int pysqlite_build_row_cast_map(pysqlite_Cursor* self)
230230
if (converter != Py_None) {
231231
Py_DECREF(converter);
232232
}
233-
Py_XDECREF(self->row_cast_map);
234-
self->row_cast_map = NULL;
233+
Py_CLEAR(self->row_cast_map);
235234

236235
return -1;
237236
}
@@ -443,8 +442,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
443442
self->locked = 1;
444443
self->reset = 0;
445444

446-
Py_XDECREF(self->next_row);
447-
self->next_row = NULL;
445+
Py_CLEAR(self->next_row);
448446

449447
if (multiple) {
450448
/* executemany() */
@@ -860,8 +858,7 @@ PyObject* pysqlite_cursor_iternext(pysqlite_Cursor *self)
860858
if (!self->next_row) {
861859
if (self->statement) {
862860
(void)pysqlite_statement_reset(self->statement);
863-
Py_DECREF(self->statement);
864-
self->statement = NULL;
861+
Py_CLEAR(self->statement);
865862
}
866863
return NULL;
867864
}

Modules/posixmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,7 @@ typedef struct {
693693
static void
694694
path_cleanup(path_t *path) {
695695
if (path->cleanup) {
696-
Py_DECREF(path->cleanup);
697-
path->cleanup = NULL;
696+
Py_CLEAR(path->cleanup);
698697
}
699698
}
700699

Modules/pyexpat.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ call_with_frame(PyCodeObject *c, PyObject* func, PyObject* args,
314314
}
315315
else {
316316
if (trace_frame(tstate, f, PyTrace_RETURN, res) < 0) {
317-
Py_XDECREF(res);
318-
res = NULL;
317+
Py_CLEAR(res);
319318
}
320319
}
321320
#else

Modules/readline.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ set_hook(const char *funcname, PyObject **hook_var, PyObject *args)
231231
if (!PyArg_ParseTuple(args, buf, &function))
232232
return NULL;
233233
if (function == Py_None) {
234-
Py_XDECREF(*hook_var);
235-
*hook_var = NULL;
234+
Py_CLEAR(*hook_var);
236235
}
237236
else if (PyCallable_Check(function)) {
238237
PyObject *tmp = *hook_var;
@@ -827,7 +826,7 @@ on_completion_display_matches_hook(char **matches,
827826
(r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
828827
goto error;
829828
}
830-
Py_XDECREF(r); r=NULL;
829+
Py_CLEAR(r);
831830

832831
if (0) {
833832
error:

Modules/selectmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ reap_obj(pylist fd2obj[FD_SETSIZE + 1])
7474
{
7575
int i;
7676
for (i = 0; i < FD_SETSIZE + 1 && fd2obj[i].sentinel >= 0; i++) {
77-
Py_XDECREF(fd2obj[i].obj);
78-
fd2obj[i].obj = NULL;
77+
Py_CLEAR(fd2obj[i].obj);
7978
}
8079
fd2obj[0].sentinel = -1;
8180
}

Modules/signalmodule.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,12 +1305,9 @@ finisignal(void)
13051305
Py_XDECREF(func);
13061306
}
13071307

1308-
Py_XDECREF(IntHandler);
1309-
IntHandler = NULL;
1310-
Py_XDECREF(DefaultHandler);
1311-
DefaultHandler = NULL;
1312-
Py_XDECREF(IgnoreHandler);
1313-
IgnoreHandler = NULL;
1308+
Py_CLEAR(IntHandler);
1309+
Py_CLEAR(DefaultHandler);
1310+
Py_CLEAR(IgnoreHandler);
13141311
}
13151312

13161313

Modules/syslogmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ syslog_closelog(PyObject *self, PyObject *unused)
197197
{
198198
if (S_log_open) {
199199
closelog();
200-
Py_XDECREF(S_ident_o);
201-
S_ident_o = NULL;
200+
Py_CLEAR(S_ident_o);
202201
S_log_open = 0;
203202
}
204203
Py_INCREF(Py_None);

Modules/zlibmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ PyZlib_compressobj(PyObject *selfptr, PyObject *args, PyObject *kwargs)
392392
}
393393

394394
error:
395-
Py_XDECREF(self);
396-
self = NULL;
395+
Py_CLEAR(self);
397396
success:
398397
if (zdict.buf != NULL)
399398
PyBuffer_Release(&zdict);

0 commit comments

Comments
 (0)