Closed
Description
Bug report
Bug description:
Add to test_class.py
in TestInlineValues
:
def test_detach_materialized_dict_no_memory(self):
a = WithAttrs()
d = a.__dict__
_testcapi.set_nomemory(0)
del a
print(d["a"])
This will crash because the dictionary will no longer points to valid memory:
#0 Py_XINCREF (op=<unknown at remote 0xdddddddddddddddd>) at ./Include/refcount.h:456
#1 _Py_XNewRef (obj=<unknown at remote 0xdddddddddddddddd>) at ./Include/refcount.h:488
#2 _Py_dict_lookup_threadsafe (mp=mp@entry=0x7ffff778ff50, key=key@entry='a', hash=<optimized out>, value_addr=value_addr@entry=0x7fffffffb078) at Objects/dictobject.c:1544
#3 0x0000000000518457 in dict_subscript (self={'b': <unknown at remote 0xdddddddddddddddd>, 'd': <unknown at remote 0xdddddddddddddddd>, 'a': <unknown at remote 0xdddddddddddddddd>, 'c': <unknown at remote 0xdddddddddddddddd>}, key='a')
at Objects/dictobject.c:3325
#4 0x000000000049d8c6 in PyObject_GetItem (o=o@entry={'b': <unknown at remote 0xdddddddddddddddd>, 'd': <unknown at remote 0xdddddddddddddddd>, 'a': <unknown at remote 0xdddddddddddddddd>, 'c': <unknown at remote 0xdddddddddddddddd>},
key=key@entry='a') at Objects/abstract.c:158
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux