[libvirt] [PATCH 6/7] Coverity: Fix resource leak in nodeinfo.c

Daniel P. Berrange berrange at redhat.com
Wed May 2 14:58:03 UTC 2012


On Wed, May 02, 2012 at 10:51:37PM +0800, Osier Yang wrote:
> Error: RESOURCE_LEAK:
> /builddir/build/BUILD/libvirt-0.9.10/src/nodeinfo.c:629: alloc_fn: Calling allocation function "fopen".
> /builddir/build/BUILD/libvirt-0.9.10/src/nodeinfo.c:629: var_assign: Assigning: "cpuinfo" =  storage returned from "fopen("/proc/cpuinfo", "r")".
> /builddir/build/BUILD/libvirt-0.9.10/src/nodeinfo.c:638: leaked_storage: Variable "cpuinfo" going out of scope leaks the storage it points to.
> ---
>  src/nodeinfo.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/src/nodeinfo.c b/src/nodeinfo.c
> index e842474..4072da2 100644
> --- a/src/nodeinfo.c
> +++ b/src/nodeinfo.c
> @@ -636,6 +636,7 @@ int nodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) {
>      }
>  
>      if (virAsprintf(&sysfs_cpuinfo, CPU_SYS_PATH) < 0) {
> +        VIR_FORCE_FCLOSE(cpuinfo);
>          virReportOOMError();
>          return -1;
>      }

This method would really benefit from being changed to use the
'goto cleanup' style rather than duplicating cleanup in the
many 'return' statements.

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list