[vlc-commits] aout: fix aout_DevicesList() error handling
Rémi Denis-Courmont
git at videolan.org
Wed Jul 27 18:50:33 CEST 2016
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Jul 27 19:35:15 2016 +0300| [13260b30685b4ec6a9cab4e0c715bee0295dab6b] | committer: 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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=13260b30685b4ec6a9cab4e0c715bee0295dab6b
---
src/audio_output/output.c | 55 ++++++++++++++++++++++++++---------------------
1 file changed, 30 insertions(+), 25 deletions(-)
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index f5363f1..90db056 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -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;
}
More information about the vlc-commits
mailing list