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: memory leak - ast_error_finish
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: jimjjewett, nnorwitz
Priority: normal Keywords:

Created on 2005-11-30 16:41 by jimjjewett, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg26945 - (view) Author: Jim Jewett (jimjjewett) Date: 2005-11-30 16:41
http://svn.python.org/view/python/trunk/Python/ast.c?
rev=41486&view=markup

function ast_error_finish

It first gets the errstr, for a possible early out.
If there is an error string, it is increfed, but it is 
not decrefed on the other early outs.  (lineno==-1 and 
failure to build a tmp.


"""
    Py_INCREF(errstr);
    lineno = PyInt_AsLong(PyTuple_GetItem(value, 1));
    if (lineno == -1)
return;
    Py_DECREF(value);

    loc = PyErr_ProgramText(filename, lineno);
    if (!loc) {
Py_INCREF(Py_None);
loc = Py_None;
    }
    tmp = Py_BuildValue("(ziOO)", filename, lineno, 
Py_None, loc);
    Py_DECREF(loc);
    if (!tmp)
return;
    value = Py_BuildValue("(OO)", errstr, tmp);
    Py_DECREF(errstr);
"""


msg26946 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2005-12-02 05:22
Logged In: YES 
user_id=33168

ISTM that we don't need the INCREF or DECREF for errstr.  Do
you agree?
msg26947 - (view) Author: Jim Jewett (jimjjewett) Date: 2005-12-02 19:14
Logged In: YES 
user_id=764593

No, though it took me a *long* time to see why, because the 
&value pointer is reused.

As best I understand it, PyErr_Fetch may leave (the initial 
value of) value with the only reference to errstr.

There is a Py_DECREF(value) after successfully retrieving a 
line number, but before using errstr to build the (new value 
of) value for PyErr_Restore.
msg26948 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2005-12-11 20:09
Logged In: YES 
user_id=33168

You are correct.  I thought I had tested, but test_grammar
failed with my removal.  I added the DECREFs.

Committed revision 41641.

Thanks for tracking this down.
History
Date User Action Args
2022-04-11 14:56:14adminsetgithub: 42645
2005-11-30 16:41:19jimjjewettcreate