mirror of https://github.com/python/cpython
bpo-41422: Visit the Pickler's and Unpickler's memo in tp_traverse (GH-21664)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
99a73c3465
commit
967f2a3052
|
@ -0,0 +1,2 @@
|
||||||
|
Fixed memory leaks of :class:`pickle.Pickler` and :class:`pickle.Unpickler` involving cyclic references via the
|
||||||
|
internal memo mapping.
|
|
@ -4707,6 +4707,14 @@ Pickler_traverse(PicklerObject *self, visitproc visit, void *arg)
|
||||||
Py_VISIT(self->fast_memo);
|
Py_VISIT(self->fast_memo);
|
||||||
Py_VISIT(self->reducer_override);
|
Py_VISIT(self->reducer_override);
|
||||||
Py_VISIT(self->buffer_callback);
|
Py_VISIT(self->buffer_callback);
|
||||||
|
PyMemoTable *memo = self->memo;
|
||||||
|
if (memo && memo->mt_table) {
|
||||||
|
Py_ssize_t i = memo->mt_allocated;
|
||||||
|
while (--i >= 0) {
|
||||||
|
Py_VISIT(memo->mt_table[i].me_key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7175,6 +7183,13 @@ Unpickler_traverse(UnpicklerObject *self, visitproc visit, void *arg)
|
||||||
Py_VISIT(self->stack);
|
Py_VISIT(self->stack);
|
||||||
Py_VISIT(self->pers_func);
|
Py_VISIT(self->pers_func);
|
||||||
Py_VISIT(self->buffers);
|
Py_VISIT(self->buffers);
|
||||||
|
PyObject **memo = self->memo;
|
||||||
|
if (memo) {
|
||||||
|
Py_ssize_t i = self->memo_size;
|
||||||
|
while (--i >= 0) {
|
||||||
|
Py_VISIT(memo[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue