summaryrefslogtreecommitdiff
path: root/src/common_device_name.c
diff options
context:
space:
mode:
authorIan Romanick <idr@localhost.localdomain>2006-08-10 09:46:07 -0700
committerIan Romanick <idr@localhost.localdomain>2006-08-10 09:46:07 -0700
commitd05da6520a273ee4c2f0e11b5a9bac65b51835fe (patch)
tree5fe7f54d85959943cb244e9fb516149bfd579dda /src/common_device_name.c
parent27f0ffca71277371a0b6c0cd1a720a9ce9519da5 (diff)
downloadlibpciaccess-d05da6520a273ee4c2f0e11b5a9bac65b51835fe.tar.gz
libpciaccess-d05da6520a273ee4c2f0e11b5a9bac65b51835fe.tar.bz2
libpciaccess-d05da6520a273ee4c2f0e11b5a9bac65b51835fe.zip
Fix a segfault in populate_vendor that was triggered when the pci.ids file
could not be opened. Thanks to Aaron Plattner for reporting this. Fix a couple possible memory leaks in the same function.
Diffstat (limited to 'src/common_device_name.c')
-rw-r--r--src/common_device_name.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/common_device_name.c b/src/common_device_name.c
index 96ee0ee..31ed8f2 100644
--- a/src/common_device_name.c
+++ b/src/common_device_name.c
@@ -178,6 +178,22 @@ populate_vendor( struct pci_id_leaf * vend, int fill_device_data )
unsigned vendor = PCI_MATCH_ANY;
+ /* If the pci.ids file could not be opened, there's nothing we can do.
+ */
+ if (f == NULL) {
+ return;
+ }
+
+
+ /* If the device tree for this vendor is already populated, don't do
+ * anything. This avoids wasted processing and potential memory leaks.
+ */
+ if (vend->num_devices != 0) {
+ fclose(f);
+ return;
+ }
+
+
while( fgets( buf, sizeof( buf ), f ) != NULL ) {
unsigned num_tabs;
char * new_line;
@@ -212,7 +228,12 @@ populate_vendor( struct pci_id_leaf * vend, int fill_device_data )
if ( num_tabs == 0 ) {
vendor = (unsigned) strtoul( & buf[ num_tabs ], NULL, 16 );
if ( vend->vendor == vendor ) {
- vend->vendor_name = strdup( & buf[ num_tabs + 6 ] );
+ /* vendor_name may already be set from a previous invocation
+ * of this function with fill_device_data = 0.
+ */
+ if (vend->vendor_name != NULL) {
+ vend->vendor_name = strdup( & buf[ num_tabs + 6 ] );
+ }
/* If we're not going to fill in all of the device data as
* well, then bail out now. We have all the information that