Skip to content

Fix memory leak on objects passed to init, update, or extend #1121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 3, 2025
Merged

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Apr 3, 2025

fixes #1117

@bdraco bdraco changed the title Fix memory leak on objects passed to update or extend Fix memory leak on objects passed to init, update, or extend Apr 3, 2025
Copy link

codspeed-hq bot commented Apr 3, 2025

CodSpeed Performance Report

Merging #1121 will not alter performance

Comparing fix_leak (9270505) with master (9a32040)

Summary

✅ 244 untouched benchmarks

Copy link

codecov bot commented Apr 3, 2025

Codecov Report

Attention: Patch coverage is 72.72727% with 6 lines in your changes missing coverage. Please review.

Project coverage is 91.30%. Comparing base (9a32040) to head (9270505).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
tests/test_multidict.py 72.72% 6 Missing ⚠️

❌ Your project status has failed because the head coverage (83.71%) is below the target coverage (85.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1121      +/-   ##
==========================================
- Coverage   91.36%   91.30%   -0.07%     
==========================================
  Files          52       52              
  Lines        6349     6391      +42     
  Branches      627      627              
==========================================
+ Hits         5801     5835      +34     
- Misses        113      121       +8     
  Partials      435      435              
Flag Coverage Δ
CI-GHA 91.30% <72.72%> (-0.07%) ⬇️
MyPy 83.71% <72.72%> (-0.08%) ⬇️
pytest 99.89% <ø> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@asvetlov
Copy link
Member

asvetlov commented Apr 3, 2025

Good finding.
Let's apply a little different fix.
_multidict_extend_parse_args() should incref all returned values; I suggest you don't change it.
But the caller should decref.
This is the standard practice in Python, let's keep it.

@asvetlov
Copy link
Member

asvetlov commented Apr 3, 2025

Please take a look at the current PR's state.
It fixes the bug but avoids reference stealing.
Borrowed references are dangerous, in CPython itself we are trying to get rid of them everywhere

@bdraco
Copy link
Member Author

bdraco commented Apr 3, 2025

Thanks! Thats much better and safer. 🚀

Will clean it up, add changelog, and get it shipped

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Apr 3, 2025
@bdraco bdraco marked this pull request as ready for review April 3, 2025 18:09
@bdraco bdraco requested review from asvetlov and webknjaz as code owners April 3, 2025 18:09
@bdraco bdraco merged commit 64d2dc9 into master Apr 3, 2025
45 of 47 checks passed
@bdraco bdraco deleted the fix_leak branch April 3, 2025 18:12
@bdraco
Copy link
Member Author

bdraco commented Apr 3, 2025

If you get a chance, aio-libs/yarl#1456 could use a followup review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory leak on 6.3.0, 6.3.1
2 participants