Fix some memory leaks + double free

Sylvestre Ledru <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
Hello,

The two patches fix some potential memory leaks and a double free.

Thanks,
Sylvestre

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
0002-Remove-some-potential-double-free.patch (text/x-patch, 801 B)
From e099ba02f34a8698c59e36144886502d4f58d410 Mon Sep 17 00:00:00 2001
From: Sylvestre Ledru <[email protected]>
Date: Wed, 7 May 2014 17:16:09 +0200
Subject: [PATCH 2/2] Remove some potential double free

---
 src/cairo-truetype-subset.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index 3d55fef..645a89a 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -1564,12 +1564,12 @@ _cairo_truetype_read_font_name (cairo_scaled_font_t  	 *scaled_font,
 	    goto fail;
     }
 
-    free (name);
-
     status = _cairo_escape_ps_name (&ps_name);
     if (unlikely(status))
 	goto fail;
 
+    free (name);
+
     *ps_name_out = ps_name;
     *font_name_out = family_name;
 
-- 
2.0.0.rc0
0001-Fix-some-memory-leaks-found-by-scan-build-the-LLVM-C.patch (text/x-patch, 2.3 KB)
From 3cb1dd13903014814dced740d785b101c17fd622 Mon Sep 17 00:00:00 2001
From: Sylvestre Ledru <[email protected]>
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

---
 src/cairo-cff-subset.c  | 4 +++-
 src/cairo-pdf-surface.c | 4 +++-
 test/pdf-mime-data.c    | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/cairo-cff-subset.c b/src/cairo-cff-subset.c
index 1ae032c..1bb9461 100644
--- a/src/cairo-cff-subset.c
+++ b/src/cairo-cff-subset.c
@@ -1851,8 +1851,10 @@ cairo_cff_font_subset_fontdict (cairo_cff_font_t  *font)
     for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) {
 	cid = font->scaled_font_subset->glyphs[i];
 	status = cairo_cff_font_get_gid_for_cid (font, cid, &gid);
-	if (unlikely (status))
+	if (unlikely (status)) {
+	    free (reverse_map);
 	    return status;
+	}
 
         fd = font->fdselect[gid];
         if (reverse_map[fd] < 0) {
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) {
+	free(global.id);
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+    }
 
     global.emitted = FALSE;
     status = _cairo_array_append (&surface->jbig2_global, &global);
diff --git a/test/pdf-mime-data.c b/test/pdf-mime-data.c
index c575c4a..e2c529e 100644
--- a/test/pdf-mime-data.c
+++ b/test/pdf-mime-data.c
@@ -105,6 +105,7 @@ preamble (cairo_test_context_t *ctx)
     test_status = read_file (ctx, IMAGE_FILE ".jpg", &data, &len);
     if (test_status) {
 	cairo_test_log (ctx, "Could not read input jpeg file %s\n", IMAGE_FILE ".jpg");
+	free(data);
 	return test_status;
     }
 
@@ -149,6 +150,7 @@ preamble (cairo_test_context_t *ctx)
     test_status = read_file (ctx, IMAGE_FILE ".jpg", &data, &len);
     if (test_status) {
 	cairo_test_log (ctx, "Could not read input jpeg file %s\n", IMAGE_FILE ".jpg");
+	free(data);
 	return test_status;
     }
 
-- 
2.0.0.rc0
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.