classification
Title: visit_decref(): add an assertion to check that the object is not freed
Type: enhancement Stage: patch review
Components: Interpreter Core Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, pablogsal, vstinner
Priority: normal Keywords: patch

Created on 2019-09-09 14:05 by vstinner, last changed 2019-09-17 22:01 by vstinner.

Files
File name Uploaded Description Edit
bpo-38037-bug.patch vstinner, 2019-09-09 14:12
Pull Requests
URL Status Linked Edit
PR 15782 merged vstinner, 2019-09-09 14:09
PR 15793 merged miss-islington, 2019-09-09 15:45
PR 16243 merged vstinner, 2019-09-17 21:03
PR 16244 merged vstinner, 2019-09-17 21:10
PR 16245 merged vstinner, 2019-09-17 21:36
PR 16246 open vstinner, 2019-09-17 22:01
Messages (9)
msg351470 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-09-09 14:05
This issue is related to bpo-36389 "Add gc.enable_object_debugger(): detect corrupted Python objects in the GC.

I propose to call _PyObject_IsFreed() in visit_decref() in debug mode, to get a better error message if something goes wrong.

visit_decref() is commonly found in C traceback (ex: gdb backtrace) of bugs related to the garbage collector.
msg351473 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-09-09 14:12
> visit_decref() is commonly found in C traceback (ex: gdb backtrace) of bugs related to the garbage collector.

Example with attached bpo-38037-bug.patch: you can apply this patch on the master branch to reintroduce  bpo-38037 bug.

vstinner@apu$ git apply bpo-38037-bug.patch
vstinner@apu$ make

Without PR 15782:

vstinner@apu$ ./python -c pass 
Segmentation fault (core dumped)


With PR 15782:

vstinner@apu$ ./python -c pass 
Modules/gcmodule.c:379: visit_decref: Assertion "!_PyObject_IsFreed(op)" failed
<object: freed>
Fatal Python error: _PyObject_AssertFailed

Current thread 0x00007f171a280740 (most recent call first):
Aborted (core dumped)


The bug is catched earlier. And Python provides more information.
msg351504 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-09-09 15:45
New changeset d91d4de31745fc1ed4c7e6c208917827c9c472b6 by Victor Stinner in branch 'master':
bpo-38070: visit_decref() calls _PyObject_IsFreed() (GH-15782)
https://github.com/python/cpython/commit/d91d4de31745fc1ed4c7e6c208917827c9c472b6
msg351537 - (view) Author: miss-islington (miss-islington) Date: 2019-09-09 17:18
New changeset 5731172bb1e958b1d80b18eaf88d3f2f93cfccdd by Miss Islington (bot) in branch '3.8':
bpo-38070: visit_decref() calls _PyObject_IsFreed() (GH-15782)
https://github.com/python/cpython/commit/5731172bb1e958b1d80b18eaf88d3f2f93cfccdd
msg351645 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-09-10 13:16
Should this be closed now?
msg351686 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-09-10 14:48
> Should this be closed now?

Please keep it open, I have a few more local changess to enhance Py_FatalError() :-) I would like to reuse the bpo number.
msg352665 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-09-17 21:36
New changeset 8fa3e1740b3f03ea65ddb68411c2238c5f98eec2 by Victor Stinner in branch 'master':
bpo-38070: _Py_DumpTraceback() writes <no Python frame> (GH-16244)
https://github.com/python/cpython/commit/8fa3e1740b3f03ea65ddb68411c2238c5f98eec2
msg352666 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-09-17 21:36
New changeset b39afb78768418d9405c4b528c80fa968ccc974d by Victor Stinner in branch 'master':
bpo-38070: Enhance _PyObject_Dump() (GH-16243)
https://github.com/python/cpython/commit/b39afb78768418d9405c4b528c80fa968ccc974d
msg352667 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-09-17 21:59
New changeset d3b904144e86e2442961de6a7dccecbe133d5c6d by Victor Stinner in branch 'master':
bpo-38070: Add _PyRuntimeState.preinitializing (GH-16245)
https://github.com/python/cpython/commit/d3b904144e86e2442961de6a7dccecbe133d5c6d
History
Date User Action Args
2019-09-17 22:01:20vstinnersetpull_requests: + pull_request15842
2019-09-17 21:59:55vstinnersetmessages: + msg352667
2019-09-17 21:36:55vstinnersetpull_requests: + pull_request15841
2019-09-17 21:36:31vstinnersetmessages: + msg352666
2019-09-17 21:36:19vstinnersetmessages: + msg352665
2019-09-17 21:10:37vstinnersetpull_requests: + pull_request15840
2019-09-17 21:03:18vstinnersetpull_requests: + pull_request15839
2019-09-10 14:48:40vstinnersetmessages: + msg351686
2019-09-10 13:16:49pablogsalsetnosy: + pablogsal
messages: + msg351645
2019-09-09 17:18:12miss-islingtonsetnosy: + miss-islington
messages: + msg351537
2019-09-09 15:45:12miss-islingtonsetpull_requests: + pull_request15446
2019-09-09 15:45:02vstinnersetmessages: + msg351504
2019-09-09 14:12:09vstinnersetfiles: + bpo-38037-bug.patch

messages: + msg351473
2019-09-09 14:09:45vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request15435
2019-09-09 14:05:36vstinnercreate