[vlc-commits] aout: use checked allocs in aout_DevicesList
Francois Cartegnie
git at videolan.org
Wed Jul 20 16:25:02 CEST 2016
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Jul 19 18:57:23 2016 +0200| [aefc9ee2fe90730819f18c0f66ea8e6f883fd413] | committer: Francois Cartegnie
aout: use checked allocs in aout_DevicesList
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=aefc9ee2fe90730819f18c0f66ea8e6f883fd413
---
src/audio_output/output.c | 39 ++++++++++++++++++++++++++++++---------
1 file changed, 30 insertions(+), 9 deletions(-)
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index c5d850b..f5363f1 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -692,20 +692,41 @@ int aout_DevicesList (audio_output_t *aout, char ***ids, char ***names)
{
aout_owner_t *owner = aout_owner (aout);
char **tabid, **tabname;
- unsigned count;
+ unsigned count = 0;
vlc_mutex_lock (&owner->dev.lock);
- count = owner->dev.count;
- tabid = xmalloc (sizeof (*tabid) * count);
- tabname = xmalloc (sizeof (*tabname) * count);
- *ids = tabid;
- *names = tabname;
- for (aout_dev_t *dev = owner->dev.list; dev != NULL; dev = dev->next)
+ tabid = malloc (sizeof (*tabid) * owner->dev.count);
+ tabname = malloc (sizeof (*tabname) * owner->dev.count);
+ if(likely(tabid && tabname))
{
- *(tabid++) = xstrdup (dev->id);
- *(tabname++) = xstrdup (dev->name);
+ 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;
+ }
+
+ tabid[count] = psz_id;
+ tabname[count++] = psz_name;
+ }
}
vlc_mutex_unlock (&owner->dev.lock);
+ if(unlikely(count == 0))
+ {
+ free(tabid);
+ free(tabname);
+ return -1;
+ }
+
+ *ids = tabid;
+ *names = tabname;
+
return count;
}
More information about the vlc-commits
mailing list