[PATCH:libpciaccess] Close pci.ids file when bailing out because realloc failed

Alan Coopersmith alan.coopersmith at oracle.com
Wed Feb 8 22:10:14 PST 2012


Error: File Leak
   Leaked File f
      at line 272 of src/common_device_name.c in function 'populate_vendor'.
        f initialized at line 204 with fopen("/usr/share/hwdata/pci.ids", "r").

[ This bug was found by the Parfait 0.5.0 bug checking tool.
  For more information see http://labs.oracle.com/projects/parfait/ ]

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 src/common_device_name.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/common_device_name.c b/src/common_device_name.c
index 8e8a752..8feaf69 100644
--- a/src/common_device_name.c
+++ b/src/common_device_name.c
@@ -269,7 +269,7 @@ populate_vendor( struct pci_id_leaf * vend, int fill_device_data )
 	    d = realloc( vend->devices, (vend->num_devices + 1)
 			 * sizeof( struct pci_device_leaf ) );
 	    if ( d == NULL ) {
-		return;
+		goto cleanup;
 	    }
 
 	    last_dev = & d[ vend->num_devices - 1 ];
@@ -302,6 +302,7 @@ populate_vendor( struct pci_id_leaf * vend, int fill_device_data )
 	}
     }
 
+  cleanup:
     pci_id_file_close( f );
 }
 
-- 
1.7.3.2



More information about the xorg-devel mailing list