From: Martin Ling Date: Sun, 3 Nov 2013 20:50:01 +0000 (+0000) Subject: Always return an empty port list unless allocation fails. X-Git-Tag: libserialport-0.1.0~153 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=24c1a4bb053e517a55eb0f6355b8f362659d4caf;p=libserialport.git Always return an empty port list unless allocation fails. --- diff --git a/serialport.c b/serialport.c index e8de069..ce306fd 100644 --- a/serialport.c +++ b/serialport.c @@ -45,14 +45,6 @@ #include "serialport.h" -static char **sp_list_new(void) -{ - char **list; - if ((list = malloc(sizeof(char *)))) - list[0] = NULL; - return list; -} - static char **sp_list_append(char **list, void *data, size_t len) { void *tmp; @@ -78,7 +70,12 @@ fail: */ char **sp_list_ports(void) { - char **list = NULL; + char **list; + + if (!(list = malloc(sizeof(char *)))) + return NULL; + + list[0] = NULL; #ifdef _WIN32 HKEY key; @@ -98,8 +95,6 @@ char **sp_list_ports(void) goto out_close; if (!(data = malloc((max_data_len + 1) * sizeof(TCHAR)))) goto out_free_value; - if (!(list = sp_list_new())) - goto out; while ( value_len = max_value_len, data_size = max_data_size, @@ -146,9 +141,6 @@ out_close: if (!(path = malloc(PATH_MAX))) goto out_release; - if (!(list = sp_list_new())) - goto out; - while ((port = IOIteratorNext(iter))) { cf_path = IORegistryEntryCreateCFProperty(port, CFSTR(kIOCalloutDeviceKey), kCFAllocatorDefault, 0); @@ -189,8 +181,6 @@ out_release: udev_enumerate_add_match_subsystem(ud_enumerate, "tty"); udev_enumerate_scan_devices(ud_enumerate); ud_list = udev_enumerate_get_list_entry(ud_enumerate); - if (!(list = sp_list_new())) - goto out; udev_list_entry_foreach(ud_entry, ud_list) { path = udev_list_entry_get_name(ud_entry);