qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [5509] Keep usb host scanning from leaking file descriptors
Date: Tue, 21 Oct 2008 16:34:20 +0000	[thread overview]
Message-ID: <E1KsKBY-0001HX-RC@cvs.savannah.gnu.org> (raw)

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;
 }
 

                 reply	other threads:[~2008-10-21 16:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1KsKBY-0001HX-RC@cvs.savannah.gnu.org \
    --to=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).