Skip to content

don't decref borrowed references#19

Open
florolf wants to merge 1 commit into
alsa-project:masterfrom
florolf:dont-decref-borrowed
Open

don't decref borrowed references#19
florolf wants to merge 1 commit into
alsa-project:masterfrom
florolf:dont-decref-borrowed

Conversation

@florolf

@florolf florolf commented Mar 12, 2026

Copy link
Copy Markdown

This has always been wrong, but since Python 3.14 restructured some memory management code in python/cpython@5716cc3, this now causes Python to segfault:

$ cat a.py
from pyalsa import alsamixer

m=alsamixer.Mixer()
m.attach()
m.load()
e=alsamixer.Element(m, 'Master')
e.set_volume_tuple([0,0])
$
$ for i in $(seq 1 100); do python -Xfaulthandler a.py || break; done
Fatal Python error: Segmentation fault

Current thread 0x00007f01f2854b80 [python] (most recent call first):
  Garbage-collecting
  <no Python frame>

Current thread's C stack trace (most recent call first):
  Binary file "/usr/lib/libpython3.14.so.1.0", at _Py_DumpStack+0x4d [0x7f01f233731c]
  Binary file "/usr/lib/libpython3.14.so.1.0", at +0x13c250 [0x7f01f233c250]
  Binary file "/usr/lib/libc.so.6", at +0x3e2d0 [0x7f01f204d2d0]
  Binary file "/usr/lib/libpython3.14.so.1.0", at +0x21960d [0x7f01f241960d]
  Binary file "/usr/lib/libpython3.14.so.1.0", at +0x219187 [0x7f01f2419187]
  Binary file "/usr/lib/libpython3.14.so.1.0", at +0x26bf38 [0x7f01f246bf38]
  Binary file "/usr/lib/libpython3.14.so.1.0", at +0x28ff64 [0x7f01f248ff64]
  Binary file "/usr/lib/libpython3.14.so.1.0", at Py_RunMain+0x37a [0x7f01f245e59a]
  Binary file "/usr/lib/libpython3.14.so.1.0", at Py_BytesMain+0x3b [0x7f01f2457c6b]
  Binary file "/usr/lib/libc.so.6", at +0x276c1 [0x7f01f20366c1]
  Binary file "/usr/lib/libc.so.6", at __libc_start_main+0x89 [0x7f01f20367f9]
  Binary file "python", at _start+0x25 [0x55f22cd3e045]

Extension modules: pyalsa.alsamixer (total: 1)

This PR fixes all instances of this behavior in the code base.

PyArg_ParseTuple does not increment the reference count of objects
returned from the "O" format specifier, so we must not DECREF them.

Signed-off-by: Florian Larysch <larysch@fixme.gmbh>
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 this pull request may close these issues.

1 participant