Repository navigation
Commit 4440c96
authored
Fix reference leak when decoding msgpack Ext payloads (#1109)
Fixes #1108.
`Ext_New` doesn't steal the reference to `data` (it does its own
`Py_INCREF`, matching the borrow contract expected by the `Ext`
constructor). Both decode branches in `mpack_decode_ext` (typed `Ext`
decode, and `Any` decode without an `ext_hook`) passed a fresh reference
from `PyBytes_FromStringAndSize` and never released it, leaking one
bytes object (the ext payload) per decoded Ext. The `datetime` (code -1)
and `ext_hook` branches were not affected.
The fix releases the caller's reference after constructing the `Ext`,
same pattern as the `Raw.copy()` leak fix (#709). Verified empirically:
RSS delta over 200k decodes of a 1 KiB payload went from ~205 MiB to 0
on both affected branches; the new test fails before the fix
(`sys.getrefcount` 3 vs 2) and passes after.
Thanks @K-ANOY for the precise report, the ownership analysis there was
spot on.
Co-authored-by: Siyet <[email protected]>1 parent 52ae4f1 commit 4440c96
2 files changed
Lines changed: 18 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16486 | 16486 | | |
16487 | 16487 | | |
16488 | 16488 | | |
16489 | | - | |
| 16489 | + | |
| 16490 | + | |
| 16491 | + | |
| 16492 | + | |
16490 | 16493 | | |
16491 | 16494 | | |
16492 | 16495 | | |
| |||
16503 | 16506 | | |
16504 | 16507 | | |
16505 | 16508 | | |
16506 | | - | |
| 16509 | + | |
| 16510 | + | |
| 16511 | + | |
| 16512 | + | |
16507 | 16513 | | |
16508 | 16514 | | |
16509 | 16515 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1339 | 1339 | | |
1340 | 1340 | | |
1341 | 1341 | | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
1342 | 1352 | | |
1343 | 1353 | | |
1344 | 1354 | | |
| |||
0 commit comments