[issue24992] collections.OrderedDict constructor (odict_new) doesn't handle PyDict_New() failure

Serhiy Storchaka report at bugs.python.org
Thu Sep 3 15:57:28 CEST 2015


Serhiy Storchaka added the comment:

If don't initialize fields, then they will be not initialized in odict_dealloc, odict_tp_clear and odict_traverse. But _odict_FIRST(od) and od->od_weakreflist are used in these functions.

I would allocate a dict for od_inst_dict before calling PyDict_Type.tp_new. An allocator can release GIL and call Python code, and at that moment the OrderedDict object is in inconsistent state. I already were fell in similar trap with lru_cache (issue14373, msg246573).

----------
nosy: +rhettinger, serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24992>
_______________________________________


More information about the Python-bugs-list mailing list