fix crashes when accessing already closed devices

PCM.htimestamp() gets the usual exception emission,
Mixer.close() gets a "double invocation" check like PCM.close() has.
This commit is contained in:
Oswald Buddenhagen
2022-08-05 19:17:19 +02:00
parent 379fc05b5e
commit a7b9d617b2
+11 -4
View File
@@ -890,6 +890,11 @@ alsapcm_htimestamp(alsapcm_t *self, PyObject *args)
snd_pcm_uframes_t avail;
PyObject *result = NULL;
if (!self->handle) {
PyErr_SetString(ALSAAudioError, "PCM device is closed");
return NULL;
}
snd_pcm_htimestamp(self->handle , &avail, &tstamp);
result = PyTuple_New(3);
@@ -2146,10 +2151,12 @@ alsamixer_close(alsamixer_t *self, PyObject *args)
if (!PyArg_ParseTuple(args,":close"))
return NULL;
snd_mixer_close(self->handle);
free(self->cardname);
free(self->controlname);
self->handle = 0;
if (self->handle) {
snd_mixer_close(self->handle);
free(self->cardname);
free(self->controlname);
self->handle = 0;
}
Py_INCREF(Py_None);
return Py_None;