From 664141e34c4df3aed6c21996e2476175d136c06b Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Mon, 16 Jan 2023 03:12:52 -0800 Subject: [PATCH] gh-101056: Fix memory leak in `formatfloat()` in `bytesobject.c` (GH-101057) (cherry picked from commit b1a74a182d8762bda51838401ac92b6ebad9632a) Co-authored-by: Nikita Sobolev --- Objects/bytesobject.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index eaedb0b5689b..4bcb2eb49298 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -470,8 +470,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; -- 2.47.3