Commit 32e0ca8
committed
[mypyc] Fix memory leak when borrowing property getter return values
`is_native_attr_ref()` uses `has_attr(name) and not get_method(name)` to
decide if an attribute access can borrow. `has_attr()` is populated
during preparation (always complete), but `get_method()` checks
`ir.methods` which is populated during compilation. When cross-module
classes haven't been compiled yet, `get_method()` returns None for
property getters, incorrectly allowing borrowing.
Property getters return new owned references, so skipping the DECREF
leaks one reference per call.
The fix checks `ir.attributes` directly (struct fields only, always
populated during preparation). Properties are never in `ir.attributes`,
so they always return False.
This is the getter-side counterpart to python#21095.1 parent 19cf4d9 commit 32e0ca8
2 files changed
Lines changed: 45 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1553 | 1553 | | |
1554 | 1554 | | |
1555 | 1555 | | |
1556 | | - | |
1557 | | - | |
| 1556 | + | |
1558 | 1557 | | |
1559 | 1558 | | |
1560 | 1559 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5925 | 5925 | | |
5926 | 5926 | | |
5927 | 5927 | | |
| 5928 | + | |
| 5929 | + | |
| 5930 | + | |
| 5931 | + | |
| 5932 | + | |
| 5933 | + | |
| 5934 | + | |
| 5935 | + | |
| 5936 | + | |
| 5937 | + | |
| 5938 | + | |
| 5939 | + | |
| 5940 | + | |
| 5941 | + | |
| 5942 | + | |
| 5943 | + | |
| 5944 | + | |
| 5945 | + | |
| 5946 | + | |
| 5947 | + | |
| 5948 | + | |
| 5949 | + | |
| 5950 | + | |
| 5951 | + | |
| 5952 | + | |
| 5953 | + | |
| 5954 | + | |
| 5955 | + | |
| 5956 | + | |
| 5957 | + | |
| 5958 | + | |
| 5959 | + | |
| 5960 | + | |
| 5961 | + | |
| 5962 | + | |
| 5963 | + | |
| 5964 | + | |
| 5965 | + | |
| 5966 | + | |
| 5967 | + | |
| 5968 | + | |
| 5969 | + | |
| 5970 | + | |
| 5971 | + | |
0 commit comments