]> xenbits.xensource.com Git - libvirt.git/commitdiff
don't leak a file descriptor on failed pciGetDevice call
authorJim Meyering <meyering@redhat.com>
Tue, 3 Mar 2009 11:25:35 +0000 (11:25 +0000)
committerJim Meyering <meyering@redhat.com>
Tue, 3 Mar 2009 11:25:35 +0000 (11:25 +0000)
* src/pci.c (pciIterDevices): Always close dir handle.

ChangeLog
src/pci.c

index 903c92292b7418c931d5adab3746ad20ae752ba6..bae760e6935fbe2d475f348b76d70327b8e721e9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Mar 3 12:22:51 +0100 2009 Jim Meyering <meyering@redhat.com>
+
+       don't leak a file descriptor on failed pciGetDevice call
+       * src/pci.c (pciIterDevices): Always close dir handle.
+
 Tue Mar 3 12:22:51 +0100 2009 Jim Meyering <meyering@redhat.com>
 
        update .gitignore and .hgignore files
index 2343be3e74a35545130f0e85fb54467b81f7e6ea..29a6dcc2000d82213679860bc9acce216fa2cc09 100644 (file)
--- a/src/pci.c
+++ b/src/pci.c
@@ -233,6 +233,7 @@ pciIterDevices(virConnectPtr conn,
 {
     DIR *dir;
     struct dirent *entry;
+    int ret = 0;
 
     *matched = NULL;
 
@@ -252,14 +253,17 @@ pciIterDevices(virConnectPtr conn,
         if (entry->d_name[0] == '.')
             continue;
 
-        if (sscanf(entry->d_name, "%x:%x:%x.%x", &domain, &bus, &slot, &function) < 4) {
+        if (sscanf(entry->d_name, "%x:%x:%x.%x",
+                   &domain, &bus, &slot, &function) < 4) {
             VIR_WARN("Unusual entry in " PCI_SYSFS "devices: %s", entry->d_name);
             continue;
         }
 
         try = pciGetDevice(conn, domain, bus, slot, function);
-        if (!try)
-            return -1;
+        if (!try) {
+            ret = -1;
+            break;
+        }
 
         if (predicate(try, dev)) {
             VIR_DEBUG("%s %s: iter matched on %s", dev->id, dev->name, try->name);
@@ -269,7 +273,7 @@ pciIterDevices(virConnectPtr conn,
         pciFreeDevice(conn, try);
     }
     closedir(dir);
-    return 0;
+    return ret;
 }
 
 static uint8_t