X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=windows.c;h=bad62bf5806f063ce639824bdaec420c381c003d;hb=b328a48b0fd8ce51f400b5e06bc1e2ab52e3c9ae;hp=78b6ce9babf6685bed794b17bf974e09084c829f;hpb=970f279ae4767819a816573ae354813d37d5091d;p=libserialport.git diff --git a/windows.c b/windows.c index 78b6ce9..bad62bf 100644 --- a/windows.c +++ b/windows.c @@ -253,7 +253,7 @@ static void enumerate_hub(struct sp_port *port, char *hub_name, /* get the number of ports of the hub */ if (DeviceIoControl(hub_device, IOCTL_USB_GET_NODE_INFORMATION, &hub_info, size, &hub_info, size, &size, NULL)) - /* enumarate the ports of the hub */ + /* enumerate the ports of the hub */ enumerate_hub_ports(port, hub_device, hub_info.u.HubInformation.HubDescriptor.bNumberOfPorts, parent_path); @@ -353,14 +353,17 @@ SP_PRIV enum sp_return get_port_details(struct sp_port *port) CONFIGRET cr; /* check if this is the device we are looking for */ - if (!(device_key = SetupDiOpenDevRegKey(device_info, &device_info_data, - DICS_FLAG_GLOBAL, 0, - DIREG_DEV, KEY_QUERY_VALUE))) + device_key = SetupDiOpenDevRegKey(device_info, &device_info_data, + DICS_FLAG_GLOBAL, 0, + DIREG_DEV, KEY_QUERY_VALUE); + if (device_key == INVALID_HANDLE_VALUE) continue; size = sizeof(value); if (RegQueryValueExA(device_key, "PortName", NULL, &type, (LPBYTE)value, - &size) != ERROR_SUCCESS || type != REG_SZ) + &size) != ERROR_SUCCESS || type != REG_SZ) { + RegCloseKey(device_key); continue; + } RegCloseKey(device_key); value[sizeof(value)-1] = 0; if (strcmp(value, port->name)) @@ -446,12 +449,14 @@ SP_PRIV enum sp_return get_port_details(struct sp_port *port) free(escaped_port_name); CloseHandle(handle); - /* retrive USB device details from the device descriptor */ + /* retrieve USB device details from the device descriptor */ get_usb_details(port, device_info_data.DevInst); } break; } + SetupDiDestroyDeviceInfoList(device_info); + RETURN_OK(); } @@ -494,28 +499,30 @@ SP_PRIV enum sp_return list_ports(struct sp_port ***list) RegEnumValue(key, index, value, &value_len, NULL, &type, (LPBYTE)data, &data_size) == ERROR_SUCCESS) { - data_len = data_size / sizeof(TCHAR); - data[data_len] = '\0'; + if (type == REG_SZ) { + data_len = data_size / sizeof(TCHAR); + data[data_len] = '\0'; #ifdef UNICODE - name_len = WideCharToMultiByte(CP_ACP, 0, data, -1, NULL, 0, NULL, NULL); + name_len = WideCharToMultiByte(CP_ACP, 0, data, -1, NULL, 0, NULL, NULL); #else - name_len = data_len + 1; + name_len = data_len + 1; #endif - if (!(name = malloc(name_len))) { - SET_ERROR(ret, SP_ERR_MEM, "registry port name malloc failed"); - goto out; - } + if (!(name = malloc(name_len))) { + SET_ERROR(ret, SP_ERR_MEM, "registry port name malloc failed"); + goto out; + } #ifdef UNICODE - WideCharToMultiByte(CP_ACP, 0, data, -1, name, name_len, NULL, NULL); + WideCharToMultiByte(CP_ACP, 0, data, -1, name, name_len, NULL, NULL); #else - strcpy(name, data); + strcpy(name, data); #endif - if (type == REG_SZ) { - DEBUG("Found port %s", name); + DEBUG_FMT("Found port %s", name); if (!(*list = list_append(*list, name))) { SET_ERROR(ret, SP_ERR_MEM, "list append failed"); + free(name); goto out; } + free(name); } index++; }