This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bkabrda
Recipients bkabrda
Date 2013-07-08.12:57:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Function dbm_length from Modules/_gdbmmodule.c seems to be leaking memory. A simple reproducer:

import dbm

d ='spam', 'c')
d['x'] = '1'

The interesting part of valgrind output with --leak-check=full:

==3312== 1 bytes in 1 blocks are definitely lost in loss record 1 of 3,622
==3312==    at 0x4A06409: malloc (in /usr/lib64/valgrind/
==3312==    by 0x3A31A0349D: get_next_key (gdbmseq.c:72)
==3312==    by 0x3A31A03595: gdbm_nextkey (gdbmseq.c:126)
==3312==    by 0xDD74192: dbm_length (_gdbmmodule.c:104)
==3312==    by 0x3A2473F50B: builtin_len (bltinmodule.c:1293)
==3312==    by 0x3A247510D1: PyEval_EvalFrameEx (ceval.c:4080)
==3312==    by 0x3A24753758: PyEval_EvalCodeEx (ceval.c:3462)
==3312==    by 0x3A2475390A: PyEval_EvalCode (ceval.c:791)
==3312==    by 0x3A24773893: run_mod (pythonrun.c:1989)
==3312==    by 0x3A24775EE7: PyRun_FileExFlags (pythonrun.c:1945)
==3312==    by 0x3A24777000: PyRun_SimpleFileExFlags (pythonrun.c:1455)
==3312==    by 0x3A2478F72B: Py_Main (main.c:306)

It seems that the problem is in the loop here [1] - specifically, the last okey.dptr seems not to be freed (the loop is terminated when key.dptr is NULL, but okey.dptr is still pointing to something).
I'm attaching a supersimple patch that should fix this (unless I'm totally wrong about everything...)

Date User Action Args
2013-07-08 12:57:13bkabrdasetrecipients: + bkabrda
2013-07-08 12:57:13bkabrdasetmessageid: <>
2013-07-08 12:57:13bkabrdalinkissue18404 messages
2013-07-08 12:57:13bkabrdacreate