forked from auracaster/pyalsaaudio
fix memory handling in mixer access error paths
in case of error, alsamixer_new() would leak the object, while alsamixer_list() might crash due to a null pointer. as a drive-by, make alsamixer_gethandle() `static`.
This commit is contained in:
17
alsaaudio.c
17
alsaaudio.c
@@ -1904,16 +1904,18 @@ static PyTypeObject ALSAMixerType;
|
|||||||
|
|
||||||
#define MIXER_CHANNEL_ALL -1
|
#define MIXER_CHANNEL_ALL -1
|
||||||
|
|
||||||
int
|
static int
|
||||||
alsamixer_gethandle(char *cardname, snd_mixer_t **handle)
|
alsamixer_gethandle(char *cardname, snd_mixer_t **handle)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
if ((err = snd_mixer_open(handle, 0)) < 0) return err;
|
if ((err = snd_mixer_open(handle, 0)) < 0)
|
||||||
if ((err = snd_mixer_attach(*handle, cardname)) < 0) return err;
|
return err;
|
||||||
if ((err = snd_mixer_selem_register(*handle, NULL, NULL)) < 0) return err;
|
if ((err = snd_mixer_attach(*handle, cardname)) >= 0 &&
|
||||||
if ((err = snd_mixer_load(*handle)) < 0) return err;
|
(err = snd_mixer_selem_register(*handle, NULL, NULL)) >= 0 &&
|
||||||
|
(err = snd_mixer_load(*handle)) >= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
snd_mixer_close(*handle);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
@@ -1950,7 +1952,6 @@ alsamixer_list(PyObject *self, PyObject *args, PyObject *kwds)
|
|||||||
if (err < 0)
|
if (err < 0)
|
||||||
{
|
{
|
||||||
PyErr_Format(ALSAAudioError, "%s [%s]", snd_strerror(err), device);
|
PyErr_Format(ALSAAudioError, "%s [%s]", snd_strerror(err), device);
|
||||||
snd_mixer_close(handle);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user