[Python-Dev] Re: [Patch #103248] Fix a memory leak in _sre.c
Wed, 17 Jan 2001 09:12:32 +0100
Charles G Waldman wrote:
> Can you explain why you made this (seemingly arbitrary) change?
> I think that since "self" was created via:
> self = PyObject_NEW_VAR(PatternObject, &Pattern_Type, n);
> which calls PyObjectINIT, which in turn calls _Py_NewReference, which
> increments _Py_RefTotal, it is incorrect to simply do a PyObject_DEL
> to de-allocate it -- won't this screw up the value of _Py_RefTotal?
and what do you think will happen if you call the destructor before
you've initialized all pointer fields in the object?
(according to the docs, the NEW/New functions return uninitialized
memory. in this case, we're bailing out before the object has been
fully initialized. pattern_dealloc definitely isn't prepared to deal with
random pointer values...)
> Admittedly this is a minor nit and only matters if Py_TRACE_REFS is
> defined - I just wanted to check to make sure my understanding of
> reference counting w.r.t. memory allocation and deallocation is
> correct - if the above is in error, I'd apprecate any corrections...
same here. I don't doubt it's working as you say it does, but I find it
strange that you shouldn't be able to DEL an object you just created
with NEW... maybe DEL should be fixed?