Commit f16a0db323e1a8c0044696815cceeb98706f2243
1 parent
a2ffb812
Keep usb host scanning from leaking file descriptors
If the first case does not succeed, then the usb scanning code will leak file descriptors on every scan. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5509 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
11 additions
and
5 deletions
usb-linux.c
| ... | ... | @@ -1276,27 +1276,31 @@ static int usb_host_scan(void *opaque, USBScanFunc *func) |
| 1276 | 1276 | usb_fs_type = USB_FS_PROC; |
| 1277 | 1277 | fclose(f); |
| 1278 | 1278 | dprintf(opened, USBPROCBUS_PATH, devices); |
| 1279 | + goto found_devices; | |
| 1279 | 1280 | } |
| 1280 | 1281 | /* try additional methods if an access method hasn't been found yet */ |
| 1281 | 1282 | f = fopen(USBDEVBUS_PATH "/devices", "r"); |
| 1282 | - if (!usb_fs_type && f) { | |
| 1283 | + if (f) { | |
| 1283 | 1284 | /* devices found in /dev/bus/usb/ */ |
| 1284 | 1285 | strcpy(devpath, USBDEVBUS_PATH); |
| 1285 | 1286 | usb_fs_type = USB_FS_DEV; |
| 1286 | 1287 | fclose(f); |
| 1287 | 1288 | dprintf(opened, USBDEVBUS_PATH, devices); |
| 1289 | + goto found_devices; | |
| 1288 | 1290 | } |
| 1289 | 1291 | dir = opendir(USBSYSBUS_PATH "/devices"); |
| 1290 | - if (!usb_fs_type && dir) { | |
| 1292 | + if (dir) { | |
| 1291 | 1293 | /* devices found in /dev/bus/usb/ (yes - not a mistake!) */ |
| 1292 | 1294 | strcpy(devpath, USBDEVBUS_PATH); |
| 1293 | 1295 | usb_fs_type = USB_FS_SYS; |
| 1294 | 1296 | closedir(dir); |
| 1295 | 1297 | dprintf(opened, USBSYSBUS_PATH, devices); |
| 1298 | + goto found_devices; | |
| 1296 | 1299 | } |
| 1300 | + found_devices: | |
| 1297 | 1301 | if (!usb_fs_type) { |
| 1298 | 1302 | term_printf("husb: unable to access USB devices\n"); |
| 1299 | - goto the_end; | |
| 1303 | + return -ENOENT; | |
| 1300 | 1304 | } |
| 1301 | 1305 | |
| 1302 | 1306 | /* the module setting (used later for opening devices) */ |
| ... | ... | @@ -1307,7 +1311,7 @@ static int usb_host_scan(void *opaque, USBScanFunc *func) |
| 1307 | 1311 | } else { |
| 1308 | 1312 | /* out of memory? */ |
| 1309 | 1313 | perror("husb: unable to allocate memory for device path"); |
| 1310 | - goto the_end; | |
| 1314 | + return -ENOMEM; | |
| 1311 | 1315 | } |
| 1312 | 1316 | } |
| 1313 | 1317 | |
| ... | ... | @@ -1319,8 +1323,10 @@ static int usb_host_scan(void *opaque, USBScanFunc *func) |
| 1319 | 1323 | case USB_FS_SYS: |
| 1320 | 1324 | ret = usb_host_scan_sys(opaque, func); |
| 1321 | 1325 | break; |
| 1326 | + default: | |
| 1327 | + ret = -EINVAL; | |
| 1328 | + break; | |
| 1322 | 1329 | } |
| 1323 | - the_end: | |
| 1324 | 1330 | return ret; |
| 1325 | 1331 | } |
| 1326 | 1332 | ... | ... |