@@ -1642,6 +1642,30 @@ code_new_impl(PyTypeObject *type, int argcount, int posonlyargcount,
1642
1642
return co ;
1643
1643
}
1644
1644
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
+
1645
1669
static void
1646
1670
code_dealloc (PyCodeObject * co )
1647
1671
{
@@ -1688,24 +1712,7 @@ code_dealloc(PyCodeObject *co)
1688
1712
if (co -> co_weakreflist != NULL ) {
1689
1713
PyObject_ClearWeakRefs ((PyObject * )co );
1690
1714
}
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 );
1709
1716
PyObject_Free (co );
1710
1717
}
1711
1718
@@ -2288,24 +2295,7 @@ _PyStaticCode_Fini(PyCodeObject *co)
2288
2295
PyObject_ClearWeakRefs ((PyObject * )co );
2289
2296
co -> co_weakreflist = NULL ;
2290
2297
}
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 );
2309
2299
}
2310
2300
2311
2301
int
0 commit comments