Re: [PATCH] test/bitmap-font: Fix use of pointer after freed pointer

Bryce Harrington <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
On Fri, Jul 03, 2015 at 03:31:48PM +0530, Arpit Jain wrote:
>         The pointer 'filename' is already freed and still used as a function argument.
>         This patch will free the pointer 'filename' only after it is used.
> 		Also, the patch ensures that it frees the pointer 'filename' before any return of this function.
> 
>         Fixes:  https://bugs.freedesktop.org/show_bug.cgi?id=91206
> 
> Signed-off-by: Arpit Jain <[email protected]>
> ---
>  test/bitmap-font.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/test/bitmap-font.c b/test/bitmap-font.c
> index 0ec9b3d..31c31b0 100644
> --- a/test/bitmap-font.c
> +++ b/test/bitmap-font.c
> @@ -94,9 +94,9 @@ draw (cairo_t *cr, int width, int height)
>      }
>  
>      pattern = FcFreeTypeQuery ((unsigned char *)filename, 0, NULL, &face_count);
> -    free (filename);
>      if (! pattern) {
>  	cairo_test_log (ctx, "FcFreeTypeQuery failed.\n");
> +	free (filename);
>  	return cairo_test_status_from_status (ctx, CAIRO_STATUS_NO_MEMORY);
>      }
>  
> @@ -111,6 +111,7 @@ draw (cairo_t *cr, int width, int height)
>  	return cairo_test_status_from_status (ctx, status);
>      }
>  
> +    free (filename);
>      if (cairo_font_face_get_type (font_face) != CAIRO_FONT_TYPE_FT) {
>  	cairo_test_log (ctx, "Unexpected value from cairo_font_face_get_type: %d (expected %d)\n",
>  			cairo_font_face_get_type (font_face), CAIRO_FONT_TYPE_FT);
> -- 
> 1.7.9.5

Good catch.  There's one more free needed on line 111.  I've made that
update and pushed:

To ssh://git.cairographics.org/git/cairo
   dced42a..943ba26  master -> master

Bryce
-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.