]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-101056: Fix memory leak in `formatfloat()` in `bytesobject.c` (#101057)
authorNikita Sobolev <mail@sobolevn.me>
Mon, 16 Jan 2023 10:46:07 +0000 (13:46 +0300)
committerGitHub <noreply@github.com>
Mon, 16 Jan 2023 10:46:07 +0000 (16:16 +0530)
Objects/bytesobject.c

index 0fd10fa00d16fa181defac2713ba3d6083408f27..ba2c2e978c6e426990f4f51330cfc311614f24aa 100644 (file)
@@ -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;