Re: [PATCH 2/7] Coverity: Fix resource leaks in phyp driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05/02/2012 08:51 AM, Osier Yang wrote:
> Coverity logs:
> 
> Error: RESOURCE_LEAK:
> /builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:523: alloc_fn: Calling allocation function "fopen".
> /builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:523: var_assign: Assigning: "fd" =  storage returned from "fopen(local_file, "rb")".
> /builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:540: noescape: Variable "fd" is not freed or pointed-to in function "fread".
> /builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:542: noescape: Variable "fd" is not freed or pointed-to in function "feof".
> /builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:575: leaked_storage: Variable "fd" going out of scope leaks the storage it points to.
> /builddir/build/BUILD/libvirt-0.9.10/src/phyp/phyp_driver.c:585: leaked_storage: Variable "fd" going out of scope leaks the storage it points to.
> 

> --- a/src/phyp/phyp_driver.c
> +++ b/src/phyp/phyp_driver.c
> @@ -582,6 +582,7 @@ err:
>          libssh2_channel_free(channel);
>          channel = NULL;
>      }
> +    VIR_FORCE_FCLOSE(fd);
>      return -1;
>  }

ACK if you squash this in (otherwise, you can end up calling
fclose(garbage), never a good idea).  [And why did we name it fd? That's
a lousy name, because it makes me think of low-level fds for open/close,
not high-level files for fopen/fclose.]

diff --git i/src/phyp/phyp_driver.c w/src/phyp/phyp_driver.c
index b883b56..25336ef 100644
--- i/src/phyp/phyp_driver.c
+++ w/src/phyp/phyp_driver.c
@@ -491,7 +491,7 @@ phypUUIDTable_Push(virConnectPtr conn)
     struct stat local_fileinfo;
     char buffer[1024];
     int rc = 0;
-    FILE *fd;
+    FILE *fd = NULL;
     size_t nread, sent;
     char *ptr;
     char local_file[] = "./uuid_table";


-- 
Eric Blake   eblake@xxxxxxxxxx    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]