From b1a74a182d8762bda51838401ac92b6ebad9632a Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Mon, 16 Jan 2023 13:46:07 +0300 Subject: [PATCH] gh-101056: Fix memory leak in `formatfloat()` in `bytesobject.c` (#101057) --- Objects/bytesobject.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 0fd10fa00d1..ba2c2e978c6 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -434,8 +434,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;