[Python-Dev] Meaty debugging mystery

Martin v. Löwis martin@v.loewis.de
30 Jun 2003 08:11:17 +0200


Tim Peters <tim.one@comcast.net> writes:

> I don't have time to dig into this more.  Looks like a good one, though!

A quick glance shows it is a heap corruption:

#0  0xdbdbdbdb in ?? ()
#1  0x40977c40 in __bam_c_close (dbc=0x826c058, root_pgno=0, rmroot=0x2) at ../btree/bt_cursor.c:601
#2  0x40997f37 in __db_c_close (dbc=0x826c058) at ../db/db_cam.c:135
#3  0x4054e1e3 in DBCursor_dealloc (self=0x40258d20) at /home/martin/work/py2.3/Modules/_bsddb.c:771
#4  0x080817a7 in _Py_Dealloc (op=0x40258d20) at Objects/object.c:2022
#5  0x08104e32 in frame_dealloc (f=0x826b26c) at Objects/frameobject.c:394
#6  0x080817a7 in _Py_Dealloc (op=0x826b26c) at Objects/object.c:2022
#7  0x080e65d8 in tb_dealloc (tb=0x40a57b34) at Python/traceback.c:41
#8  0x080817a7 in _Py_Dealloc (op=0x40a57b34) at Objects/object.c:2022
#9  0x080e6581 in tb_dealloc (tb=0x40a579f4) at Python/traceback.c:40
#10 0x080817a7 in _Py_Dealloc (op=0x40a579f4) at Objects/object.c:2022
#11 0x08079eaf in insertdict (mp=0x40245854, key=0x40394c28, hash=1492466088, value=0x40a6fc34)
    at Objects/dictobject.c:379
#12 0x0807a3d7 in PyDict_SetItem (op=0x40245854, key=0x40394c28, value=0x40a6fc34)
    at Objects/dictobject.c:533
#13 0x0807d710 in PyDict_SetItemString (v=0x40245854, key=0x8119310 "exc_traceback", item=0x40a6fc34)
    at Objects/dictobject.c:1976

It appears that dbc->dbp->dbenv has been freed already. Interestingly
enough, self->mydb->myenvobj->db_env is NULL, which means that
env.close() was called for it.

The specific test case triggering this problem is
test_basic.BasicMultiDBTestCase, apparently as the DBEnv is closed
before the cursor.

I'm uncertain how this could happen, as a DBEnv carries a db_ref
field, counting open databases.

Regards,
Martin