[3.13] gh-139748: fix leaks in AC error paths when using unicode FS-b… (#139792)

* [3.13] gh-139748: fix leaks in AC error paths when using unicode FS-based converters (GH-139765)
(cherry picked from commit b04a57deef)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
Kumar Aditya 2025-10-08 22:21:49 +05:30 committed by GitHub
parent d8971c21e8
commit dac827cb98
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 81 additions and 42 deletions

View file

@ -733,7 +733,7 @@ builtin_chr(PyObject *module, PyObject *i)
compile as builtin_compile
source: object
filename: object(converter="PyUnicode_FSDecoder")
filename: unicode_fs_decoded
mode: str
flags: int = 0
dont_inherit: bool = False
@ -759,7 +759,7 @@ static PyObject *
builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
const char *mode, int flags, int dont_inherit,
int optimize, int feature_version)
/*[clinic end generated code: output=b0c09c84f116d3d7 input=cc78e20e7c7682ba]*/
/*[clinic end generated code: output=b0c09c84f116d3d7 input=8f0069edbdac381b]*/
{
PyObject *source_copy;
const char *str;
@ -885,7 +885,6 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
error:
result = NULL;
finally:
Py_DECREF(filename);
return result;
}

View file

@ -291,7 +291,7 @@ builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj
PyObject *argsbuf[7];
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
PyObject *source;
PyObject *filename;
PyObject *filename = NULL;
const char *mode;
int flags = 0;
int dont_inherit = 0;
@ -361,6 +361,9 @@ skip_optional_kwonly:
return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize, feature_version);
exit:
/* Cleanup for filename */
Py_XDECREF(filename);
return return_value;
}
@ -1234,4 +1237,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
/*[clinic end generated code: output=f686ad843368963c input=a9049054013a1b77]*/
/*[clinic end generated code: output=39173c70790d9cd0 input=a9049054013a1b77]*/