Bug 6186

Summary: Memory leak in emit_image_rgb_data (src/cairo-pdf-surface.c)
Product: cairo Reporter: Ken Herron <kherron+cairo>
Component: pdf backendAssignee: Kristian Høgsberg <krh>
Status: RESOLVED FIXED QA Contact: cairo-bugs mailing list <cairo-bugs>
Severity: minor    
Priority: high    
Version: 1.1.1   
Hardware: All   
OS: All   
URL: http://gitweb.freedesktop.org/?p=cairo;a=blob;h=cb8287bcf44d4bd0173e88002c10aa7229eb5d5b;hb=1cffb39ff04bbb29bb070e42c51aa1ae6aaf5a4c;f=src/cairo-pdf-surface.c#l645
Whiteboard:
i915 platform: i915 features:

Description Ken Herron 2006-03-09 05:35:12 UTC
This was found through a coverity scan of the mozilla source tree.

In |emit_image_rgb_data| (src/cairo-pdf-surface.c) around line 645 some memory
is allocated and stored in a variable |rgb|. Around line 654
|cairo_image_surface_create| is called, which may return NULL. If it does, then
|emit_image_rgb_data| returns (at line 658) without freeing |rgb|.
Comment 1 Carl Worth 2006-03-14 07:19:10 UTC
This is now fixed in cairo 1.1.1.

-Carl

diff-tree fc51a78a1ed5f7649ce55ab30fc42939a9b295d1 (from
25cccaaa1f6d337a1a0423a298f94456e72a820a)
Author: Carl Worth <cworth@cworth.org>
Date:   Mon Mar 13 12:14:47 2006 -0800

    cairo-pdf-surface: Close memory leak during OOM handling.

    This fixes bug #6186:

        Memory leak in emit_image_rgb_data (src/cairo-pdf-surface.c)
        https://bugs.freedesktop.org/show_bug.cgi?id=6186

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index cb8287b..6d18196 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -654,8 +654,10 @@ emit_image_rgb_data (cairo_pdf_document_
        opaque = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
                                             image->width,
                                             image->height);
-       if (opaque->status)
+       if (opaque->status) {
+           free (rgb);
            return 0;
+       }

        _cairo_pattern_init_for_surface (&pattern.surface, &image->base);

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.