diff options
author | wm4 <wm4@nowhere> | 2015-10-30 15:51:26 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-10-30 15:51:26 +0100 |
commit | 05e39ec51362d9c23f0652a4ac5017a1b6489e49 (patch) | |
tree | 0e3766c65f5e698a3cb4496f9822e034de67f3ff | |
parent | 7aba3a5d96b0d3b22c9e93057b6d1b4cba0e5104 (diff) | |
download | mpv-05e39ec51362d9c23f0652a4ac5017a1b6489e49.tar.bz2 mpv-05e39ec51362d9c23f0652a4ac5017a1b6489e49.tar.xz |
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.
-rw-r--r-- | stream/ai_alsa1x.c | 6 | ||||
-rw-r--r-- | stream/ai_oss.c | 9 | ||||
-rw-r--r-- | stream/ai_sndio.c | 5 | ||||
-rw-r--r-- | stream/audio_in.c | 14 |
4 files changed, 23 insertions, 11 deletions
diff --git a/stream/ai_alsa1x.c b/stream/ai_alsa1x.c index c5dc84cfcc..8f2b774faf 100644 --- a/stream/ai_alsa1x.c +++ b/stream/ai_alsa1x.c @@ -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; diff --git a/stream/ai_oss.c b/stream/ai_oss.c index 0362f207dc..d1ef701e6e 100644 --- a/stream/ai_oss.c +++ b/stream/ai_oss.c @@ -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; } diff --git a/stream/ai_sndio.c b/stream/ai_sndio.c index 2bb47955a4..10e95cea62 100644 --- a/stream/ai_sndio.c +++ b/stream/ai_sndio.c @@ -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; } diff --git a/stream/audio_in.c b/stream/audio_in.c index 90b036f814..8ed92767c1 100644 --- a/stream/audio_in.c +++ b/stream/audio_in.c @@ -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 |