OSDN Git Service

Delay allocation of agp_info so we don't leak it on prior errors
authorAlan Coopersmith <alan.coopersmith@oracle.com>
Fri, 4 Jun 2010 23:58:56 +0000 (16:58 -0700)
committerAlan Coopersmith <alan.coopersmith@oracle.com>
Sat, 5 Jun 2010 00:00:57 +0000 (17:00 -0700)
   Memory leak of pointer 'agp_info'
        at line 119 of src/common_capability.c in function 'pci_fill_capabilities_generic'.
          'agp_info' allocated at line 107 with calloc(1, 12).
          'agp_info' leaks when err != 0 at line 118.
        at line 124 of src/common_capability.c in function 'pci_fill_capabilities_generic'.
          'agp_info' allocated at line 107 with calloc(1, 12).
          'agp_info' leaks when err != 0 at line 123.

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

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
src/common_capability.c

index 31d59eb..3963db1 100644 (file)
@@ -104,16 +104,11 @@ pci_fill_capabilities_generic( struct pci_device * dev )
        
        switch ( cap_id ) {
        case 2: {
-           struct pci_agp_info * agp_info = calloc( 1, sizeof( struct pci_agp_info ) );
+           struct pci_agp_info * agp_info;
            uint32_t agp_status;
            uint8_t agp_ver;
 
 
-           if ( agp_info == NULL ) {
-               return ENOMEM;
-           }
-
-
            err = pci_device_cfg_read_u8( dev, & agp_ver, cap_offset + 2 );
            if ( err ) {
                return err;
@@ -124,6 +119,11 @@ pci_fill_capabilities_generic( struct pci_device * dev )
                return err;
            }
 
+           agp_info = calloc( 1, sizeof( struct pci_agp_info ) );
+           if ( agp_info == NULL ) {
+               return ENOMEM;
+           }
+
            agp_info->config_offset = cap_offset;
 
            agp_info->major_version = (agp_ver & 0x0f0) >> 4;