Re: [libvirt] [PATCH] trying to close some potential FILE * leaks

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

 



On Fri, Mar 13, 2009 at 06:20:21PM +0100, Daniel Veillard wrote:
>  While reviewing the code due to what seems to be a FILE * leak I
> found the following problems, probably not what got me in troubles but
> should still be fixed,

ACK, all looks good.

Daniel

> Index: qemud/qemud.c
> ===================================================================
> RCS file: /data/cvs/libxen/qemud/qemud.c,v
> retrieving revision 1.146
> diff -u -p -u -r1.146 qemud.c
> --- qemud/qemud.c	3 Mar 2009 08:25:50 -0000	1.146
> +++ qemud/qemud.c	13 Mar 2009 17:15:20 -0000
> @@ -488,7 +488,7 @@ static int qemudWritePidFile(const char 
>      if (fprintf(fh, "%lu\n", (unsigned long)getpid()) < 0) {
>          VIR_ERROR(_("Failed to write to pid file '%s' : %s"),
>                    pidFile, virStrerror(errno, ebuf, sizeof ebuf));
> -        close(fd);
> +        fclose(fh);
>          return -1;
>      }
>  
> Index: src/cgroup.c
> ===================================================================
> RCS file: /data/cvs/libxen/src/cgroup.c,v
> retrieving revision 1.9
> diff -u -p -u -r1.9 cgroup.c
> --- src/cgroup.c	6 Mar 2009 14:44:05 -0000	1.9
> +++ src/cgroup.c	13 Mar 2009 17:15:21 -0000
> @@ -57,7 +57,7 @@ void virCgroupFree(virCgroupPtr *group)
>  
>  static virCgroupPtr virCgroupGetMount(const char *controller)
>  {
> -    FILE *mounts;
> +    FILE *mounts = NULL;
>      struct mntent entry;
>      char buf[CGROUP_MAX_VAL];
>      virCgroupPtr root = NULL;
> @@ -90,6 +90,8 @@ static virCgroupPtr virCgroupGetMount(co
>  
>      return root;
>  err:
> +    if (mounts != NULL)
> +        fclose(mounts);
>      virCgroupFree(&root);
>  
>      return NULL;
> Index: src/uml_driver.c
> ===================================================================
> RCS file: /data/cvs/libxen/src/uml_driver.c,v
> retrieving revision 1.25
> diff -u -p -u -r1.25 uml_driver.c
> --- src/uml_driver.c	3 Mar 2009 09:14:28 -0000	1.25
> +++ src/uml_driver.c	13 Mar 2009 17:15:21 -0000
> @@ -546,6 +546,7 @@ reopen:
>  
>      if (fscanf(file, "%d", &vm->pid) != 1) {
>          errno = EINVAL;
> +        fclose(file);
>          goto cleanup;
>      }
>  
> @@ -1039,6 +1040,7 @@ static int umlGetProcessInfo(unsigned lo
>  
>      if (fscanf(pidinfo, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %llu %llu", &usertime, &systime) != 2) {
>          umlDebug("not enough arg");
> +        fclose(pidinfo);
>          return -1;
>      }
>  
> Index: src/util.c
> ===================================================================
> RCS file: /data/cvs/libxen/src/util.c,v
> retrieving revision 1.93
> diff -u -p -u -r1.93 util.c
> --- src/util.c	3 Mar 2009 12:03:44 -0000	1.93
> +++ src/util.c	13 Mar 2009 17:15:21 -0000
> @@ -1058,6 +1058,7 @@ int virFileReadPid(const char *dir,
>  
>      if (fscanf(file, "%d", pid) != 1) {
>          rc = EINVAL;
> +        fclose(file);
>          goto cleanup;
>      }
>  

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


-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
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]