[Xcb] Patch to fix memory leak.

Barton C Massey bart at cs.pdx.edu
Wed Aug 6 12:39:09 PDT 2008


Thanks much for the patch!

However, excuse my naivete, but is this the best patch?
Wouldn't it have been better to just add the single
free(rep) line at the end?  Thanks also for any
clarification you might have.

    Bart

In message <mailman.35.1218049216.17565.xcb-commit at lists.freedesktop.org> you wrote:
> New commits:
> commit 73d2e818e5a4ec362061cd95031a0cf2d8d02f96
> Author: Julien Danjou <julien at danjou.info>
> Date:   Wed Aug 6 16:23:36 2008 +0200
> 
>     icccm: fix memory leak in xcb_get_wm_hints()
>     
>     Signed-off-by: Julien Danjou <julien at danjou.info>
> 
> diff --git a/icccm/icccm.c b/icccm/icccm.c
> index ff89d3e..250c4c3 100644
> --- a/icccm/icccm.c
> +++ b/icccm/icccm.c
> @@ -670,7 +670,7 @@ xcb_get_wm_hints (xcb_connection_t *c,
>                    xcb_window_t      window)
>  {
>  	xcb_get_property_cookie_t cookie;
> -	xcb_get_property_reply_t *rep;
> +	xcb_get_property_reply_t *rep = NULL;
>  	xcb_wm_hints_t           *hints;
>  	long                      length;
>  
> @@ -685,22 +685,19 @@ xcb_get_wm_hints (xcb_connection_t *c,
>  	if ((rep->type != WM_HINTS) ||
>  	    (length < (XCB_NUM_WM_HINTS_ELEMENTS - 1)) ||
>  	    (rep->format != 32))
> -	{
> -		free (rep);
> -		return NULL;
> -	}
> +            goto bailout;
> +
>  	hints = xcb_alloc_wm_hints();
>  	if (!hints)
> -	{
> -		free (rep);
> -		return NULL;
> -	}
> +            goto bailout;
>  
>  	memcpy(hints, (xcb_size_hints_t *) xcb_get_property_value (rep),
>  	       length * rep->format >> 3);
>  	if (length < XCB_NUM_WM_HINTS_ELEMENTS)
>  		hints->window_group = XCB_NONE;
>  
> +    bailout:
> +        free(rep);
>  	return hints;
>  }


More information about the Xcb mailing list