Skip to content
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

Bad reference counting in the _warnings module #66216

Closed
xdegaye mannequin opened this issue Jul 20, 2014 · 3 comments
Closed

Bad reference counting in the _warnings module #66216

xdegaye mannequin opened this issue Jul 20, 2014 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@xdegaye
Copy link
Mannequin

xdegaye mannequin commented Jul 20, 2014

BPO 22017
Nosy @brettcannon, @xdegaye

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:

assignee = None
closed_at = <Date 2014-07-20.20:04:49.002>
created_at = <Date 2014-07-20.16:24:34.599>
labels = ['interpreter-core', 'type-crash']
title = 'Bad reference counting in the _warnings module'
updated_at = <Date 2014-07-20.20:04:48.987>
user = 'https://github.com/xdegaye'

bugs.python.org fields:

activity = <Date 2014-07-20.20:04:48.987>
actor = 'python-dev'
assignee = 'none'
closed = True
closed_date = <Date 2014-07-20.20:04:49.002>
closer = 'python-dev'
components = ['Interpreter Core']
creation = <Date 2014-07-20.16:24:34.599>
creator = 'xdegaye'
dependencies = []
files = []
hgrepos = []
issue_num = 22017
keywords = []
message_count = 3.0
messages = ['223519', '223520', '223535']
nosy_count = 3.0
nosy_names = ['brett.cannon', 'xdegaye', 'python-dev']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'crash'
url = 'https://bugs.python.org/issue22017'
versions = ['Python 2.7']

@xdegaye
Copy link
Mannequin Author

xdegaye mannequin commented Jul 20, 2014

$ ./python
Python 2.7.8+ (2.7:5563f895b215, Jul 20 2014, 18:10:28) 
[GCC 4.9.0 20140521 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import warnings
>>> warnings.defaultaction = 'default'
>>> warnings.warn('some warning')
__main__:1: UserWarning: some warning
>>> exit()
Fatal Python error: Objects/dictobject.c:519 object at 0x7fce2013e2e0 has negative ref count -2604246222170760230
Aborted (core dumped)

The following patch fixes this: the new string object is referenced both by the static variable '_default_action' and the module attribute 'default_action'.
Python 3.5 handles this correctly.
The same kind of fix should also be applied to '_once_registry' and '_filters'.

diff --git a/Python/_warnings.c b/Python/_warnings.c
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -903,6 +903,7 @@
         return;
 
     _default_action = PyString_FromString("default");
+    Py_INCREF(_default_action);
     if (_default_action == NULL)
         return;
     if (PyModule_AddObject(m, "default_action", _default_action) < 0)

@xdegaye xdegaye mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Jul 20, 2014
@xdegaye
Copy link
Mannequin Author

xdegaye mannequin commented Jul 20, 2014

The same kind of fix should also be applied to '_once_registry' and '_filters'.

Oops, no they are correctly refcounted.

@python-dev
Copy link
Mannequin

python-dev mannequin commented Jul 20, 2014

New changeset 8106f91fccd6 by Benjamin Peterson in branch '2.7':
correct ref counting of default_action (closes bpo-22017)
http://hg.python.org/cpython/rev/8106f91fccd6

@python-dev python-dev mannequin closed this as completed Jul 20, 2014
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

0 participants