From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KsKBa-00084E-NW for qemu-devel@nongnu.org; Tue, 21 Oct 2008 12:34:22 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KsKBa-00083f-6o for qemu-devel@nongnu.org; Tue, 21 Oct 2008 12:34:22 -0400 Received: from [199.232.76.173] (port=54324 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KsKBa-00083a-1q for qemu-devel@nongnu.org; Tue, 21 Oct 2008 12:34:22 -0400 Received: from savannah.gnu.org ([199.232.41.3]:43787 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KsKBZ-0003un-OZ for qemu-devel@nongnu.org; Tue, 21 Oct 2008 12:34:21 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1KsKBZ-0001Hb-2W for qemu-devel@nongnu.org; Tue, 21 Oct 2008 16:34:21 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1KsKBY-0001HX-RC for qemu-devel@nongnu.org; Tue, 21 Oct 2008 16:34:20 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Tue, 21 Oct 2008 16:34:20 +0000 Subject: [Qemu-devel] [5509] Keep usb host scanning from leaking file descriptors Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 5509 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5509 Author: aliguori Date: 2008-10-21 16:34:20 +0000 (Tue, 21 Oct 2008) Log Message: ----------- 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. Modified Paths: -------------- trunk/usb-linux.c Modified: trunk/usb-linux.c =================================================================== --- trunk/usb-linux.c 2008-10-21 16:31:31 UTC (rev 5508) +++ trunk/usb-linux.c 2008-10-21 16:34:20 UTC (rev 5509) @@ -1276,27 +1276,31 @@ usb_fs_type = USB_FS_PROC; fclose(f); dprintf(opened, USBPROCBUS_PATH, devices); + goto found_devices; } /* try additional methods if an access method hasn't been found yet */ f = fopen(USBDEVBUS_PATH "/devices", "r"); - if (!usb_fs_type && f) { + if (f) { /* devices found in /dev/bus/usb/ */ strcpy(devpath, USBDEVBUS_PATH); usb_fs_type = USB_FS_DEV; fclose(f); dprintf(opened, USBDEVBUS_PATH, devices); + goto found_devices; } dir = opendir(USBSYSBUS_PATH "/devices"); - if (!usb_fs_type && dir) { + if (dir) { /* devices found in /dev/bus/usb/ (yes - not a mistake!) */ strcpy(devpath, USBDEVBUS_PATH); usb_fs_type = USB_FS_SYS; closedir(dir); dprintf(opened, USBSYSBUS_PATH, devices); + goto found_devices; } + found_devices: if (!usb_fs_type) { term_printf("husb: unable to access USB devices\n"); - goto the_end; + return -ENOENT; } /* the module setting (used later for opening devices) */ @@ -1307,7 +1311,7 @@ } else { /* out of memory? */ perror("husb: unable to allocate memory for device path"); - goto the_end; + return -ENOMEM; } } @@ -1319,8 +1323,10 @@ case USB_FS_SYS: ret = usb_host_scan_sys(opaque, func); break; + default: + ret = -EINVAL; + break; } - the_end: return ret; }