gh-101056: Fix memory leak in formatfloat() in bytesobject.c (GH-101057)

(cherry picked from commit b1a74a182d)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2023-01-16 03:12:23 -08:00 committed by GitHub
parent 855b1a935e
commit 63690e9af8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -441,8 +441,10 @@ formatfloat(PyObject *v, int flags, int prec, int type,
len = strlen(p);
if (writer != NULL) {
str = _PyBytesWriter_Prepare(writer, str, len);
if (str == NULL)
if (str == NULL) {
PyMem_Free(p);
return NULL;
}
memcpy(str, p, len);
PyMem_Free(p);
str += len;