10000 gh-106843: fix memleak in _PyCompile_CleanDoc (#106846) · python/cpython@ece3b9d · GitHub
[go: up one dir, main page]

Skip to content

Commit ece3b9d

Browse files
authored
gh-106843: fix memleak in _PyCompile_CleanDoc (#106846)
1 parent 1e36ca6 commit ece3b9d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Python/compile.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2267,6 +2267,7 @@ compiler_function_body(struct compiler *c, stmt_ty s, int is_async, Py_ssize_t f
22672267
}
22682268
}
22692269
if (compiler_add_const(c->c_const_cache, c->u, docstring ? docstring : Py_None) < 0) {
2270+
Py_XDECREF(docstring);
22702271
compiler_exit_scope(c);
22712272
return ERROR;
22722273
}
@@ -8060,7 +8061,9 @@ _PyCompile_CleanDoc(PyObject *doc)
80608061
}
80618062

80628063
Py_DECREF(doc);
8063-
return PyUnicode_FromStringAndSize(buff, w - buff);
8064+
PyObject *res = PyUnicode_FromStringAndSize(buff, w - buff);
8065+
PyMem_Free(buff);
8066+
return res;
80648067
}
80658068

80668069

0 commit comments

Comments
 (0)
0