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.

classification
Title: _lsprof (cProfile): Profiler.clear() keeps references to detroyed nodes
Type: crash Stage:
Components: Extension Modules Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: alexandre.vassalotti, vstinner
Priority: normal Keywords: patch

Created on 2009-12-13 19:05 by vstinner, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
_lsprof.patch vstinner, 2009-12-13 19:05
Messages (5)
msg96346 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-12-13 19:05
clearEntries() delete all nodes of the profiler tree, but 
currentProfilerContext keeps a reference to a tree node 
(currentProfilerContext->previous->header attribute).

The patch fixes clearEntries() to delete all references (destroy 
currentProfilerContext and set it to NULL).
msg96347 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-12-13 19:11
The crash is an Heisenbug (read object which just has been destroyed, 
sometimes it works, sometimes it crash), so it's not easy the write a 
short example showing the crash.

The code looks like:

   import cProfile
   prof = cProfile.Profile()
   prof.enable()
   prof.clear()

The next instruction will be analyzed by the profiler, but the profiler 
will crash in: ptrace_enter_call()->initContext()->getSubEntry()-
>Rotating_Tree_Get(&caller->calls, entry), because caller->calls node is 
invalid.
msg96348 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-12-13 19:15
See also issue #3952.
msg100361 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-03-04 00:34
Sorry, but I'm unable to write a reliable unit test. You have to trust me: the patch fixes the issue and the issue does exist :-)

Fixed by r78641 (trunk), r78642 (py3k), r78643 (3.1).

Leave this issue open until the fix can be backported to 2.6 (after 2.6.5 release).
msg101423 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-03-21 13:39
> Fixed by r78641 (trunk)

Backport done: r79200 (2.6).
History
Date User Action Args
2022-04-11 14:56:55adminsetgithub: 51743
2010-03-21 13:39:04vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg101423
2010-03-04 00:34:31vstinnersetmessages: + msg100361
2010-01-13 08:18:39pitrousetnosy: + alexandre.vassalotti
2009-12-13 19:15:39vstinnersetmessages: + msg96348
2009-12-13 19:11:30vstinnersetmessages: + msg96347
2009-12-13 19:05:40vstinnercreate