ppaez / alsaseq

ALSA sequencer bindings for Python
GNU General Public License v2.0
6 stars 6 forks source link

Calling functions before initializing module causes application crash #5

Closed djordjeglbvc closed 7 years ago

djordjeglbvc commented 7 years ago

If any of the functions from this module are called before the call to alsaseq.client(), python application crashes.

Example to reproduce:

$ python
>>> import alsaseq
>>> alsaseq.fd()
python: seq.c:1063: snd_seq_poll_descriptors_count: Assertion `seq' failed.
Aborted (core dumped)

Same happens in both python 2.7.6 and 3.5.2

djordjeglbvc commented 7 years ago

I've done a quick fix locally by adding following snippet to all functions using seq_handle object, just after if (!PyArg_ParseTuple(args, "" )):

    if (!seq_handle) {
        PyErr_SetString(PyExc_RuntimeError, "Must initialize module with alsaseq.client() before using it");
        return NULL;
    }

and now it raises RuntimeError instead of crashing.

ppaez commented 7 years ago

This is very helpful for new users! Tested ok using Python 2.7.13rc1 and 3.5.2 in Debian, merged #6