Commit 13260b30 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

aout: fix aout_DevicesList() error handling

Return -1 if and only if there was an error. Never return an incomplete
list, and do not pretend an error occurred when the devices list is
merely empty.
parent 6344700e
...@@ -692,41 +692,46 @@ int aout_DevicesList (audio_output_t *aout, char ***ids, char ***names) ...@@ -692,41 +692,46 @@ int aout_DevicesList (audio_output_t *aout, char ***ids, char ***names)
{ {
aout_owner_t *owner = aout_owner (aout); aout_owner_t *owner = aout_owner (aout);
char **tabid, **tabname; char **tabid, **tabname;
unsigned count = 0; unsigned i = 0;
vlc_mutex_lock (&owner->dev.lock); vlc_mutex_lock (&owner->dev.lock);
tabid = malloc (sizeof (*tabid) * owner->dev.count); tabid = malloc (sizeof (*tabid) * owner->dev.count);
tabname = malloc (sizeof (*tabname) * owner->dev.count); tabname = malloc (sizeof (*tabname) * owner->dev.count);
if(likely(tabid && tabname))
{
for (aout_dev_t *dev = owner->dev.list; dev != NULL; dev = dev->next)
{
char *psz_id = strdup (dev->id);
if(unlikely(psz_id == NULL))
break;
char *psz_name = strdup (dev->name); if (unlikely(tabid == NULL || tabname == NULL))
if(unlikely(psz_name == NULL)) goto error;
{
free(psz_id); *ids = tabid;
break; *names = tabname;
}
for (aout_dev_t *dev = owner->dev.list; dev != NULL; dev = dev->next)
{
tabid[i] = strdup(dev->id);
if (unlikely(tabid[i] == NULL))
goto error;
tabid[count] = psz_id; tabname[i] = strdup(dev->name);
tabname[count++] = psz_name; if (unlikely(tabname[i] == NULL))
{
free(tabid[i]);
goto error;
} }
i++;
} }
vlc_mutex_unlock (&owner->dev.lock); vlc_mutex_unlock (&owner->dev.lock);
if(unlikely(count == 0)) return i;
error:
vlc_mutex_unlock(&owner->dev.lock);
while (i > 0)
{ {
free(tabid); i--;
free(tabname); free(tabname[i]);
return -1; free(tabid[i]);
} }
free(tabname);
*ids = tabid; free(tabid);
*names = tabname; return -1;
return count;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment