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: partially initialized heap allocated type objects
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ehuss, tim.peters
Priority: normal Keywords: patch

Created on 2004-06-26 23:47 by ehuss, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
typeobject.c.patch ehuss, 2004-06-26 23:47 fix to handle dealloc of partially initialized heap allocated type objects
Messages (3)
msg46243 - (view) Author: Eric Huss (ehuss) Date: 2004-06-26 23:47
There is a problem if you try to dealloc a partially 
initialized heap allocated type object.  Because 
PyObject_GC_TRACK is not typically called until 
initialization is done, the gc_refs value is set to 
GC_UNTRACKED.

In type_dealloc, it calls _PyObject_GC_UNTRACK which 
skips the check to see if it is GC_UNTRACKED.

This patch fixes it so that it calls PyObject_GC_UnTrack 
to correctly handle this case.
msg46244 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-07-05 22:26
Logged In: YES 
user_id=31435

Well, it's not intended that type_dealloc be robust against 
insane objects.  If you leave type->tp_base (etc, etc) in an 
insane (or uninitialized) state, type_dealloc may blow up too, 
or lead to arbitrary memory corruption.

Why is the gc tracking status special?  One way it's special is 
that it's a place we *can* stick a useful assert to warn you 
when you're passing an insane object to type_dealloc -- 
explicitly initializing the gc_refs member to the untracked 
state is one of the few pieces of initialization done by the gc 
malloc functions.  The patch would disable that sanity check, 
so is unattractive on that count.
msg46245 - (view) Author: Eric Huss (ehuss) Date: 2004-07-06 02:24
Logged In: YES 
user_id=393416

To be honest, I didn't realize that _PyObject_GC_TRACK was 
being called in PyType_GenericAlloc in the type_new() 
function.  It was a problem with my code trying to make type 
objects.  Just have to remember to call gc_track early on.

History
Date User Action Args
2022-04-11 14:56:05adminsetgithub: 40467
2004-06-26 23:47:08ehusscreate