diff options
author | Oren Milman <orenmn@gmail.com> | 2018-02-13 10:28:33 (GMT) |
---|---|---|
committer | INADA Naoki <methane@users.noreply.github.com> | 2018-02-13 10:28:33 (GMT) |
commit | d019bc8319ea35e93bf4baa38098ff1b57cd3ee5 (patch) | |
tree | d9b927eba02059f8be8465d35b6969254b172b8e /Modules | |
parent | aec7532ed3ccbd29d3429a3f375e25f956c44003 (diff) | |
download | cpython-d019bc8319ea35e93bf4baa38098ff1b57cd3ee5.zip cpython-d019bc8319ea35e93bf4baa38098ff1b57cd3ee5.tar.gz cpython-d019bc8319ea35e93bf4baa38098ff1b57cd3ee5.tar.bz2 |
bpo-31787: Prevent refleaks when calling __init__() more than once (GH-3995)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_asynciomodule.c | 28 | ||||
-rw-r--r-- | Modules/_bz2module.c | 2 | ||||
-rw-r--r-- | Modules/_hashopenssl.c | 4 | ||||
-rw-r--r-- | Modules/_lzmamodule.c | 2 |
4 files changed, 23 insertions, 13 deletions
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index e82425b..d66cc4c 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -458,6 +458,7 @@ future_schedule_callbacks(FutureObj *fut) return 0; } + static int future_init(FutureObj *fut, PyObject *loop) { @@ -465,6 +466,19 @@ future_init(FutureObj *fut, PyObject *loop) int is_true; _Py_IDENTIFIER(get_debug); + // Same to FutureObj_clear() but not clearing fut->dict + Py_CLEAR(fut->fut_loop); + Py_CLEAR(fut->fut_callback0); + Py_CLEAR(fut->fut_context0); + Py_CLEAR(fut->fut_callbacks); + Py_CLEAR(fut->fut_result); + Py_CLEAR(fut->fut_exception); + Py_CLEAR(fut->fut_source_tb); + + fut->fut_state = STATE_PENDING; + fut->fut_log_tb = 0; + fut->fut_blocking = 0; + if (loop == Py_None) { loop = get_event_loop(); if (loop == NULL) { @@ -474,7 +488,7 @@ future_init(FutureObj *fut, PyObject *loop) else { Py_INCREF(loop); } - Py_XSETREF(fut->fut_loop, loop); + fut->fut_loop = loop; res = _PyObject_CallMethodId(fut->fut_loop, &PyId_get_debug, NULL); if (res == NULL) { @@ -486,16 +500,12 @@ future_init(FutureObj *fut, PyObject *loop) return -1; } if (is_true) { - Py_XSETREF(fut->fut_source_tb, _PyObject_CallNoArg(traceback_extract_stack)); + fut->fut_source_tb = _PyObject_CallNoArg(traceback_extract_stack); if (fut->fut_source_tb == NULL) { return -1; } } - fut->fut_callback0 = NULL; - fut->fut_context0 = NULL; - fut->fut_callbacks = NULL; - return 0; } @@ -1938,16 +1948,16 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop) return -1; } - self->task_context = PyContext_CopyCurrent(); + Py_XSETREF(self->task_context, PyContext_CopyCurrent()); if (self->task_context == NULL) { return -1; } - self->task_fut_waiter = NULL; + Py_CLEAR(self->task_fut_waiter); self->task_must_cancel = 0; self->task_log_destroy_pending = 1; Py_INCREF(coro); - self->task_coro = coro; + Py_XSETREF(self->task_coro, coro); if (task_call_step_soon(self, NULL)) { return -1; diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c index dba0e19..0789b61 100644 --- a/Modules/_bz2module.c +++ b/Modules/_bz2module.c @@ -644,7 +644,7 @@ _bz2_BZ2Decompressor___init___impl(BZ2Decompressor *self) self->bzs_avail_in_real = 0; self->input_buffer = NULL; self->input_buffer_size = 0; - self->unused_data = PyBytes_FromStringAndSize(NULL, 0); + Py_XSETREF(self->unused_data, PyBytes_FromStringAndSize(NULL, 0)); if (self->unused_data == NULL) goto error; diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c index 44d3f63..b6dcc06 100644 --- a/Modules/_hashopenssl.c +++ b/Modules/_hashopenssl.c @@ -369,8 +369,8 @@ EVP_tp_init(EVPobject *self, PyObject *args, PyObject *kwds) return -1; } - self->name = name_obj; - Py_INCREF(self->name); + Py_INCREF(name_obj); + Py_XSETREF(self->name, name_obj); if (data_obj) { if (view.len >= HASHLIB_GIL_MINSIZE) { diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c index fd3bbb8..5bcd088 100644 --- a/Modules/_lzmamodule.c +++ b/Modules/_lzmamodule.c @@ -1173,7 +1173,7 @@ _lzma_LZMADecompressor___init___impl(Decompressor *self, int format, self->needs_input = 1; self->input_buffer = NULL; self->input_buffer_size = 0; - self->unused_data = PyBytes_FromStringAndSize(NULL, 0); + Py_XSETREF(self->unused_data, PyBytes_FromStringAndSize(NULL, 0)); if (self->unused_data == NULL) goto error; |