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)
{
aout_owner_t *owner = aout_owner (aout);
char **tabid, **tabname;
unsigned count = 0;
unsigned i = 0;
vlc_mutex_lock (&owner->dev.lock);
tabid = malloc (sizeof (*tabid) * 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(psz_name == NULL))
{
free(psz_id);
break;
}
if (unlikely(tabid == NULL || tabname == NULL))
goto error;
*ids = tabid;
*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[count++] = psz_name;
tabname[i] = strdup(dev->name);
if (unlikely(tabname[i] == NULL))
{
free(tabid[i]);
goto error;
}
i++;
}
vlc_mutex_unlock (&owner->dev.lock);
if(unlikely(count == 0))
return i;
error:
vlc_mutex_unlock(&owner->dev.lock);
while (i > 0)
{
free(tabid);
free(tabname);
return -1;
i--;
free(tabname[i]);
free(tabid[i]);
}
*ids = tabid;
*names = tabname;
return count;
free(tabname);
free(tabid);
return -1;
}
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