• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aio-libs / multidict / 35635177744
87%

Build:
DEFAULT BRANCH: master
Ran 21 Sep 2026 05:57PM UTC
Jobs 1
Files 39
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

21 Sep 2026 05:56PM UTC coverage: 87.573% (-0.06%) from 87.63%
35635177744

push

github

web-flow
Fix key and value refleak when a table resize fails on insert (#1507)

<!-- Thank you for your contribution! -->

## What do these changes do?

`_md_add_with_hash()` and `_md_add_for_upd()` in `hashtable.h` incref
the identity, key and value and pass them to the `*_steal_refs()`
variants, which return -1 without consuming them when growing the table
fails. A `MemoryError` at that point leaked one reference to each. Both
wrappers now release them on failure. A plain `Py_DECREF` is safe even
inside an update batch that otherwise defers decrefs, since the caller
still holds its own references and none of the counts can reach zero.

The direct `*_steal_refs()` callers in `md_update_from_dict()`,
`md_update_from_kwnames()` and `md_update_from_seq()` already clean up
on failure, so they are unchanged. The pure-Python backend has no manual
refcounting and needs no change.

The new test fails the n-th allocation with `_testcapi.set_nomemory()`
for each n until the call succeeds, feeding items one at a time so the
table grows mid-insert, and checks the key and value refcounts after
every attempt. Without the fix it fails for `add`, `setdefault`,
`__setitem__`, `update` and `merge`. It is marked `c_extension` and does
not run on the pure-Python leg, because failing allocations inside
interpreted code hits CPython's own unraisable-error paths and leaves
refs held by a stray traceback.

## Are there changes in behavior for the user?

No, apart from the leak being gone.

## Is it a substantial burden for the maintainers to support this?

No.

## Related issue number

N/A. The same fix is bundled in #1505, which will drop its copy once
this lands.

## Checklist

- [x] I think the code is well written
- [x] Unit tests for the changes exist
- [x] Documentation reflects the changes (N/A, internal)
- [ ] If you provide code modification, please add yourself to
`CONTRIBUTORS.txt` (N/A)
- [x] Add a new news fragment into the `CHANGES/` folder
- [x] `make doc-spelling` pa... (continued)

762 of 1524 branches covered (50.0%)

Branch coverage included in aggregate %.

25 of 34 new or added lines in 1 file covered. (73.53%)

6588 of 6869 relevant lines covered (95.91%)

1.92 hits per line

Uncovered Changes

Lines Coverage ∆ File
9
97.57
-1.4% tests/test_mutable_multidict.py
Jobs
ID Job ID Ran Files Coverage
1 MyPy - 35635177744.1 21 Sep 2026 05:57PM UTC 78
87.57
GitHub Action Run
Source Files on build 35635177744
  • Tree
  • List 39
  • Changed 4
  • Source Changed 1
  • Coverage Changed 4
Coverage ∆ File Lines Relevant Covered Missed Hits/Line Branch Hits Branch Misses
  • Back to Repo
  • Github Actions Build #35635177744
  • 6306226e on github
  • Prev Build on master (#35633331248)
  • Next Build on master (#35637336834)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc