]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-101056: Fix memory leak in `formatfloat()` in `bytesobject.c` (GH-101057)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 16 Jan 2023 11:12:52 +0000 (03:12 -0800)
committerGitHub <noreply@github.com>
Mon, 16 Jan 2023 11:12:52 +0000 (03:12 -0800)
(cherry picked from commit b1a74a182d8762bda51838401ac92b6ebad9632a)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Objects/bytesobject.c

index eaedb0b5689b2ad92927e3f0c730ec43e9b9e202..4bcb2eb49298d7adf4317615597ceeec70009739 100644 (file)
@@ -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;