[cairo] Fix some memory leaks + double free

Uli Schlachter psychon at znc.in
Thu May 8 12:45:17 PDT 2014


On 07.05.2014 19:04, Sylvestre Ledru wrote:
> From 3cb1dd13903014814dced740d785b101c17fd622 Mon Sep 17 00:00:00 2001
> From: Sylvestre Ledru <sylvestre at mozilla.com>
> Date: Wed, 7 May 2014 17:15:22 +0200
> Subject: [PATCH 1/2] Fix some memory leaks found by scan-build, the LLVM/Clang
>  static analyzer
[...]
> diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
> index c200c28..8e92df2 100644
> --- a/src/cairo-pdf-surface.c
> +++ b/src/cairo-pdf-surface.c
> @@ -2645,8 +2645,10 @@ _cairo_pdf_surface_lookup_jbig2_global (cairo_pdf_surface_t       *surface,
>      memcpy (global.id, global_id, global_id_length);
>      global.id_length = global_id_length;
>      global.res = _cairo_pdf_surface_new_object (surface);
> -    if (global.res.id == 0)
> +    if (global.res.id == 0) {

Could you make this "if (global.id == NULL || global.res.id == 0) {"?

Hm, no, would also have to free global.res in this case... Uhm...

Add a check for malloc() failure after the line that sets global.id, please.

> +	free(global.id);
>  	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
> +    }
>  
>      global.emitted = FALSE;
>      status = _cairo_array_append (&surface->jbig2_global, &global);
[...]

Even without the above change (that really is a different issue than what your
patch handles):

Both patches
Reviewed-by: Uli Schlachter <psychon at znc.in>

Cheers,
Uli
-- 
- Buck, when, exactly, did you lose your mind?
- Three months ago. I woke up one morning married to a pineapple.
  An ugly pineapple... But I loved her.


More information about the cairo mailing list