ao_alsa: fix minor memory leak

So snd_device_name_get_hint() return values do in fact have to be freed.

Also, change listing semantics slightly: if io==NULL, skip the entry,
instead of assuming it's an output device.
This commit is contained in:
wm4 2015-08-25 15:45:57 +02:00
parent 1ec1b4186c
commit cf94fce467
1 changed files with 11 additions and 8 deletions

View File

@ -923,15 +923,18 @@ static void list_devs(struct ao *ao, struct ao_device_list *list)
char *name = snd_device_name_get_hint(hints[n], "NAME");
char *desc = snd_device_name_get_hint(hints[n], "DESC");
char *io = snd_device_name_get_hint(hints[n], "IOID");
if (io && strcmp(io, "Output") != 0)
continue;
char desc2[1024];
snprintf(desc2, sizeof(desc2), "%s", desc ? desc : "");
for (int i = 0; desc2[i]; i++) {
if (desc2[i] == '\n')
desc2[i] = '/';
if (io && strcmp(io, "Output") == 0) {
char desc2[1024];
snprintf(desc2, sizeof(desc2), "%s", desc ? desc : "");
for (int i = 0; desc2[i]; i++) {
if (desc2[i] == '\n')
desc2[i] = '/';
}
ao_device_list_add(list, ao, &(struct ao_device_desc){name, desc2});
}
ao_device_list_add(list, ao, &(struct ao_device_desc){name, desc2});
free(name);
free(desc);
free(io);
}
snd_device_name_free_hint(hints);