0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

stream/audio: fix unchecked strdups

See #2435. It's literally a waste of time trying to fix minor memory
leaks in this old, unused, and crappy code.
This commit is contained in:
wm4 2015-10-30 15:51:26 +01:00
parent 7aba3a5d96
commit 05e39ec513
4 changed files with 23 additions and 11 deletions

View File

@ -134,7 +134,11 @@ int ai_alsa_init(audio_in_t *ai)
{
int err;
err = snd_pcm_open(&ai->alsa.handle, ai->alsa.device, SND_PCM_STREAM_CAPTURE, 0);
const char *device = ai->alsa.device;
if (!device)
device = "default";
err = snd_pcm_open(&ai->alsa.handle, device, SND_PCM_STREAM_CAPTURE, 0);
if (err < 0) {
MP_ERR(ai, "Error opening audio: %s\n", snd_strerror(err));
return -1;

View File

@ -87,11 +87,14 @@ int ai_oss_init(audio_in_t *ai)
int err;
int ioctl_param;
ai->oss.audio_fd = open(ai->oss.device, O_RDONLY | O_CLOEXEC);
const char *device = ai->oss.device;
if (!device)
device = "/dev/dsp";
ai->oss.audio_fd = open(device, O_RDONLY | O_CLOEXEC);
if (ai->oss.audio_fd < 0)
{
MP_ERR(ai, "Unable to open '%s': %s\n",
ai->oss.device, mp_strerror(errno));
MP_ERR(ai, "Unable to open '%s': %s\n", device, mp_strerror(errno));
return -1;
}

View File

@ -38,7 +38,10 @@ int ai_sndio_init(audio_in_t *ai)
{
int err;
if ((ai->sndio.hdl = sio_open(ai->sndio.device, SIO_REC, 0)) == NULL) {
const char *device = ai->sndio.device;
if (!device)
device = "default";
if ((ai->sndio.hdl = sio_open(device, SIO_REC, 0)) == NULL) {
MP_ERR(ai, "could not open sndio audio");
return -1;
}

View File

@ -45,19 +45,19 @@ int audio_in_init(audio_in_t *ai, struct mp_log *log, int type)
case AUDIO_IN_ALSA:
ai->alsa.handle = NULL;
ai->alsa.log = NULL;
ai->alsa.device = strdup("default");
ai->alsa.device = NULL;
return 0;
#endif
#if HAVE_OSS_AUDIO
case AUDIO_IN_OSS:
ai->oss.audio_fd = -1;
ai->oss.device = strdup("/dev/dsp");
ai->oss.device = NULL;
return 0;
#endif
#if HAVE_SNDIO
case AUDIO_IN_SNDIO:
ai->sndio.hdl = NULL;
ai->sndio.device = strdup("default");
ai->sndio.device = NULL;
return 0;
#endif
default:
@ -161,9 +161,11 @@ int audio_in_set_device(audio_in_t *ai, char *device)
case AUDIO_IN_ALSA:
free(ai->alsa.device);
ai->alsa.device = strdup(device);
/* mplayer cannot handle colons in arguments */
for (i = 0; i < (int)strlen(ai->alsa.device); i++) {
if (ai->alsa.device[i] == '.') ai->alsa.device[i] = ':';
if (ai->alsa.device) {
/* mplayer could not handle colons in arguments */
for (i = 0; i < (int)strlen(ai->alsa.device); i++) {
if (ai->alsa.device[i] == '.') ai->alsa.device[i] = ':';
}
}
return 0;
#endif