]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106843: fix memleak in _PyCompile_CleanDoc (#106846)
authorInada Naoki <songofacandy@gmail.com>
Tue, 18 Jul 2023 03:44:16 +0000 (12:44 +0900)
committerGitHub <noreply@github.com>
Tue, 18 Jul 2023 03:44:16 +0000 (03:44 +0000)
Python/compile.c

index b80f7c01bcd90e735b551b6a562bfa470548766f..2a735382c0cfda703c0e4c29e3b72ffd5d5359b7 100644 (file)
@@ -2267,6 +2267,7 @@ compiler_function_body(struct compiler *c, stmt_ty s, int is_async, Py_ssize_t f
         }
     }
     if (compiler_add_const(c->c_const_cache, c->u, docstring ? docstring : Py_None) < 0) {
+        Py_XDECREF(docstring);
         compiler_exit_scope(c);
         return ERROR;
     }
@@ -8060,7 +8061,9 @@ _PyCompile_CleanDoc(PyObject *doc)
     }
 
     Py_DECREF(doc);
-    return PyUnicode_FromStringAndSize(buff, w - buff);
+    PyObject *res = PyUnicode_FromStringAndSize(buff, w - buff);
+    PyMem_Free(buff);
+    return res;
 }