mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
bpo-31787: Prevent refleaks when calling __init__() more than once (GH-3995)
This commit is contained in:
parent
aec7532ed3
commit
d019bc8319
13 changed files with 105 additions and 19 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue