[Python-checkins] gh-101056: Fix memory leak in `formatfloat()` in `bytesobject.c` (#101057)

kumaraditya303 webhook-mailer at python.org
Mon Jan 16 05:46:14 EST 2023


https://github.com/python/cpython/commit/b1a74a182d8762bda51838401ac92b6ebad9632a
commit: b1a74a182d8762bda51838401ac92b6ebad9632a
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: kumaraditya303 <59607654+kumaraditya303 at users.noreply.github.com>
date: 2023-01-16T16:16:07+05:30
summary:

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

files:
M Objects/bytesobject.c

diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 0fd10fa00d16..ba2c2e978c6e 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;



More information about the Python-checkins mailing list