[poppler] poppler/CairoFontEngine.cc

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Mon Apr 13 05:20:28 PDT 2015


 poppler/CairoFontEngine.cc |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

New commits:
commit 8ca43bebf36f8da085917f28230e25524de4f4f4
Author: Jason Crain <jason at aquaticape.us>
Date:   Tue Mar 24 02:51:47 2015 -0500

    cairo: Fix memory leak in CairoFreeTypeFont::create
    
    - Free embedded font data in _ft_done_face when the cairo font is
      destroyed.
    - Free embedded font data if _ft_new_face finds it's a duplicate of an
      already open font.
    - Free embedded font data and codeToGID array if font creation fails.
    
    Bug #89952

diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc
index a5a3023..4ffbf2e 100644
--- a/poppler/CairoFontEngine.cc
+++ b/poppler/CairoFontEngine.cc
@@ -256,12 +256,16 @@ _ft_done_face (void *closure)
   else
     _ft_open_faces = data->next;
 
+  if (data->fd != -1) {
 #if defined(__SUNPRO_CC) && defined(__sun) && defined(__SVR4)
-  munmap ((char*)data->bytes, data->size);
+    munmap ((char*)data->bytes, data->size);
 #else
-  munmap (data->bytes, data->size);
+    munmap (data->bytes, data->size);
 #endif
-  close (data->fd);
+    close (data->fd);
+  } else {
+    gfree (data->bytes);
+  }
 
   FT_Done_Face (data->face);
   gfree (data);
@@ -318,6 +322,8 @@ _ft_new_face (FT_Library lib,
         munmap (tmpl.bytes, tmpl.size);
 #endif
         close (tmpl.fd);
+      } else {
+	gfree (tmpl.bytes);
       }
       *face_out = l->face;
       *font_face_out = cairo_font_face_reference (l->font_face);
@@ -533,8 +539,6 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,
     }
 
     if (! _ft_new_face (lib, fileNameC, font_data, font_data_len, &face, &font_face)) {
-      gfree(codeToGID);
-      codeToGID = NULL;
       error(errSyntaxError, -1, "could not create cid face\n");
       goto err2;
     }
@@ -555,6 +559,8 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,
  err2:
   /* hmm? */
   delete fontLoc;
+  gfree (codeToGID);
+  gfree (font_data);
   fprintf (stderr, "some font thing failed\n");
   return NULL;
 }


More information about the poppler mailing list