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

Crash in debug builds of Python #50

Open
colesbury opened this issue Jan 14, 2022 · 0 comments · May be fixed by #51
Open

Crash in debug builds of Python #50

colesbury opened this issue Jan 14, 2022 · 0 comments · May be fixed by #51

Comments

@colesbury
Copy link

The following crashes in a debug build of Python:

import gc
import pycld2
gc.collect()
Modules/gcmodule.c:114: gc_decref: Assertion "gc_get_refs(g) > 0" failed: refcount is too small
Enable tracemalloc to get the memory block allocation traceback

object address  : 0x555555a2bf70
object refcount : 4
object type     : 0x555555966400
object type name: type
object repr     : <class 'pycld2.error'>

Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
Python runtime state: initialized

Current thread 0x00007ffff7c33280 (most recent call first):
  File "<string>", line 1 in <module>
Aborted (core dumped)

The problem is that the module initialization creates two references tracked by the garbage collector, but one of them is missing a Py_INCREF. (The garbage collector works by subtracting incoming references from the reference count. In this case, the reference count is too small.)

st->error = PyErr_NewException("pycld2.error", NULL, NULL);

// Steals ref:
PyModule_AddObject(m, "error", st->error);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant