Skip to content

Commit 662c16c

Browse files
committed
Fix leak of monitoring blocks.
1 parent 7b32d79 commit 662c16c

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

Objects/codeobject.c

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,30 @@ code_new_impl(PyTypeObject *type, int argcount, int posonlyargcount,
16421642
return co;
16431643
}
16441644

1645+
static void
1646+
free_monitoring_data(_PyCoMonitoringData *data)
1647+
{
1648+
if (data == NULL) {
1649+
return;
1650+
}
1651+
if (data->tools) {
1652+
PyMem_Free(data->tools);
1653+
}
1654+
if (data->lines) {
1655+
PyMem_Free(data->lines);
1656+
}
1657+
if (data->line_tools) {
1658+
PyMem_Free(data->line_tools);
1659+
}
1660+
if (data->per_instruction_opcodes) {
1661+
PyMem_Free(data->per_instruction_opcodes);
1662+
}
1663+
if (data->per_instruction_tools) {
1664+
PyMem_Free(data->per_instruction_tools);
1665+
}
1666+
PyMem_Free(data);
1667+
}
1668+
16451669
static void
16461670
code_dealloc(PyCodeObject *co)
16471671
{
@@ -1688,24 +1712,7 @@ code_dealloc(PyCodeObject *co)
16881712
if (co->co_weakreflist != NULL) {
16891713
PyObject_ClearWeakRefs((PyObject*)co);
16901714
}
1691-
_PyCoMonitoringData *data = co->_co_monitoring;
1692-
if (data) {
1693-
if (data->tools) {
1694-
PyMem_Free(data->tools);
1695-
}
1696-
if (data->lines) {
1697-
PyMem_Free(data->lines);
1698-
}
1699-
if (data->line_tools) {
1700-
PyMem_Free(data->line_tools);
1701-
}
1702-
if (data->per_instruction_opcodes) {
1703-
PyMem_Free(data->per_instruction_opcodes);
1704-
}
1705-
if (data->per_instruction_tools) {
1706-
PyMem_Free(data->per_instruction_tools);
1707-
}
1708-
}
1715+
free_monitoring_data(co->_co_monitoring);
17091716
PyObject_Free(co);
17101717
}
17111718

@@ -2288,24 +2295,7 @@ _PyStaticCode_Fini(PyCodeObject *co)
22882295
PyObject_ClearWeakRefs((PyObject *)co);
22892296
co->co_weakreflist = NULL;
22902297
}
2291-
_PyCoMonitoringData *data = co->_co_monitoring;
2292-
if (data) {
2293-
if (data->tools) {
2294-
PyMem_Free(data->tools);
2295-
}
2296-
if (data->lines) {
2297-
PyMem_Free(data->lines);
2298-
}
2299-
if (data->line_tools) {
2300-
PyMem_Free(data->line_tools);
2301-
}
2302-
if (data->per_instruction_opcodes) {
2303-
PyMem_Free(data->per_instruction_opcodes);
2304-
}
2305-
if (data->per_instruction_tools) {
2306-
PyMem_Free(data->per_instruction_tools);
2307-
}
2308-
}
2298+
free_monitoring_data(co->_co_monitoring);
23092299
}
23102300

23112301
int

0 commit comments

Comments
 (0)