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
Memory leak in curses.panel #62313
Comments
Objects associated to the panel with panel.set_userptr() are never DECREF()ed. Attached file is script to reproduce the leak. Confirmed with Python2.7/3.3. |
New changeset aff0bdab358e by Andrew Kuchling in branch '2.7': |
New changeset 3d75bd69e5a9 by Andrew Kuchling in branch '3.3': |
Thanks for the bug report! I've committed a fix to the 2.7 and 3.3 branches that retrieves the existing userptr and Py_DECREFs it if it's not null. This seems to fix the leak. |
There is a problem with this patch. Py_XDECREF can execute arbitrary Python code and this code can call set_panel_userptr. Here is a reproducer (it causes segfault). |
And here is a patch which fixes a segfault. But I can't write a test for it. |
serhiy.storchaka: good point! I wonder if, for strict correctness, we should only incref obj (the new object) if set_panel_userptr() returns OK and not an error code. I've attached a new version of the patch that does this check, and also adds a test. (OTOH, looking at the ncurses 5.9 source code, set_panel_userptr() only returns an error if the panel object is NULL, which should never happen because Python reports an error if the panel creation fails. So maybe the rc == ERR check is pointless.) |
You are right. Your patch LGTM.
Future versions or alternative implementations can returns an error in other circumstances. |
New changeset 99733ff98a50 by Andrew Kuchling in branch '2.7': |
New changeset 61fafef4c8a2 by Andrew Kuchling in branch '3.3': |
I believe the most recent 2 commits fix the segfault problem, so I'll now close this again. Please re-open if there are further issues with the bugfix. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: