From: Alan Coopersmith Date: Fri, 4 Jun 2010 23:58:56 +0000 (-0700) Subject: Delay allocation of agp_info so we don't leak it on prior errors X-Git-Tag: libpciaccess-0.12.0~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fa7cca617583eb93a862c5ebbb5a56843210e5a8;p=platform%2Fupstream%2Flibpciaccess.git Delay allocation of agp_info so we don't leak it on prior errors 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 --- diff --git a/src/common_capability.c b/src/common_capability.c index 31d59eb..3963db1 100644 --- a/src/common_capability.c +++ b/src/common_capability.c @@ -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;