提交 8343dcb8 编写于 作者: J Jim Meyering

don't leak a file descriptor on failed pciGetDevice call

* src/pci.c (pciIterDevices): Always close dir handle.
上级 26008232
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> Tue Mar 3 12:22:51 +0100 2009 Jim Meyering <meyering@redhat.com>
update .gitignore and .hgignore files update .gitignore and .hgignore files
......
...@@ -233,6 +233,7 @@ pciIterDevices(virConnectPtr conn, ...@@ -233,6 +233,7 @@ pciIterDevices(virConnectPtr conn,
{ {
DIR *dir; DIR *dir;
struct dirent *entry; struct dirent *entry;
int ret = 0;
*matched = NULL; *matched = NULL;
...@@ -252,14 +253,17 @@ pciIterDevices(virConnectPtr conn, ...@@ -252,14 +253,17 @@ pciIterDevices(virConnectPtr conn,
if (entry->d_name[0] == '.') if (entry->d_name[0] == '.')
continue; 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); VIR_WARN("Unusual entry in " PCI_SYSFS "devices: %s", entry->d_name);
continue; continue;
} }
try = pciGetDevice(conn, domain, bus, slot, function); try = pciGetDevice(conn, domain, bus, slot, function);
if (!try) if (!try) {
return -1; ret = -1;
break;
}
if (predicate(try, dev)) { if (predicate(try, dev)) {
VIR_DEBUG("%s %s: iter matched on %s", dev->id, dev->name, try->name); VIR_DEBUG("%s %s: iter matched on %s", dev->id, dev->name, try->name);
...@@ -269,7 +273,7 @@ pciIterDevices(virConnectPtr conn, ...@@ -269,7 +273,7 @@ pciIterDevices(virConnectPtr conn,
pciFreeDevice(conn, try); pciFreeDevice(conn, try);
} }
closedir(dir); closedir(dir);
return 0; return ret;
} }
static uint8_t static uint8_t
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册