You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Free resource before raise syntax error so we can access python file after syntax error. #3843
@dpgeorge, I was about to open an issue for this problem, so I can provide additional information on why I think it's a problem.
mp_lexer_free() calls lex->reader.close(lex->reader.data);. When parsing a file on disk (e.g., foo.py as a result of import foo), we end up keeping a handle open to that file if throwing an exception in mp_parse() or fold_constants(). I'm not sure if other functions called from mp_parse() can throw an exception or not. Perhaps it's safest if mp_parse() has a wrapper that calls mp_lexer_free() and re-throws the exception? I'd like some feedback on that idea before actually implementing it, though. It seems "right" since mp_parse() already takes responsibility for freeing the lexer (and closing the reader) on success.
I have a similar fix I plan to submit for mp_raw_code_load(), the equivalent import code path for loading .mpy files.
@tomlogic thanks for the info. I agree with your analysis, mp_parse() does have the responsibility to free the lexer. If it didn't catch the exception then the caller would need to.
micropython/py/parse.c
Line 1156 in aace60a