From 678149cde792d30beca94ba6fc9ea20996f2febc Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Thu, 9 Jan 2014 11:31:49 +0100 Subject: device/client: make device_get_list() allocate the result buffer itself Using device_get_count() and device_get_list() separately can return different device counts in case there are devices added to the list inbetween these two function calls. To prevent this, device_get_list() will allocate the buffer by itself. --- src/device.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/device.c') diff --git a/src/device.c b/src/device.c index 29be9d1..0844499 100644 --- a/src/device.c +++ b/src/device.c @@ -746,10 +746,15 @@ int device_get_count(int include_hidden) return count; } -int device_get_list(int include_hidden, struct device_info *p) +int device_get_list(int include_hidden, struct device_info **devices) { int count = 0; pthread_mutex_lock(&device_list_mutex); + + int total_count = collection_count(&device_list); + *devices = malloc(sizeof(struct device_info) * total_count); + struct device_info *p = *devices; + FOREACH(struct mux_device *dev, &device_list) { if((dev->state == MUXDEV_ACTIVE) && (include_hidden || dev->visible)) { p->id = dev->id; -- cgit v1.1-32-gdbae