[PATCH xhost] Resource cleanup fixes

Alan Coopersmith Alan.Coopersmith at Sun.COM
Mon Mar 22 13:59:31 PDT 2010


Reviewed-by: Alan Coopersmith <alan.coopersmith at sun.com>

Jeff Smith wrote:
> Running xhost through valgrind (with no arguments to xhost) produced
> "still reachable: 27,720 bytes in 25 blocks."  This patch reduces this to
> "still reachable: 15 bytes in 1 blocks."
> 
> Signed-off-by: Jeff Smith <whydoubt at yahoo.com>
> ---
>  xhost.c |    7 +++++--
>  1 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/xhost.c b/xhost.c
> index 2b4784a..f0fba73 100644
> --- a/xhost.c
> +++ b/xhost.c
> @@ -278,14 +278,16 @@ main(int argc, char *argv[])
>  		} else
>  		    printf("\n");
>  	    }
> -	    free(list);
> -	    endhostent();
> +	    XFree(list);
>  	}
> +	endhostent();
> +	XCloseDisplay(dpy);
>  	exit(0);
>      }
>   
>      if (argc == 2 && !strcmp(argv[1], "-help")) {
>  	fprintf(stderr, "usage: %s [[+-]hostname ...]\n", argv[0]);
> +	XCloseDisplay(dpy);
>  	exit(1);
>      }
>  
> @@ -364,6 +366,7 @@ change_host(Display *dpy, char *name, Bool add)
>      namelen = strlen(name);
>      if ((lname = (char *)malloc(namelen+1)) == NULL) {
>  	fprintf (stderr, "%s: malloc bombed in change_host\n", ProgramName);
> +	XCloseDisplay (dpy);
>  	exit (1);
>      }
>      for (i = 0; i < namelen; i++) {

-- 
	-Alan Coopersmith-           alan.coopersmith at sun.com
	 Oracle Solaris Platform Engineering: X Window System



More information about the xorg-devel mailing list