[poppler] [PATCH] mem leak when loading embedded font

Krzysztof Kowalczyk kkowalczyk at gmail.com
Sat Jul 29 14:47:33 PDT 2006


Hello,

The attached patch fixes memory leak when loading an embedded font in
Splash backend.

fontsrc is not correctly unrefed and the tmpBuf from readEmbFontFile() is
not freed.

The leak is in tens of kilobytes per font (obviously depends on the size of
embedded font file).

I noticed it because I wrote a test app to stress-test and benchmark
poppler rendering and after running on hundreds of PDF files it failed
with "out of memory" error (on a 4GB RAM machine).

In my tests, after this fix, poppler is mem-leak free.

This is also filed as bug 7687
(https://bugs.freedesktop.org/show_bug.cgi?id=7687)

Regards,

-- kjk (http://blog.kowalczyk.info)
-------------- next part --------------
Index: SplashOutputDev.cc
===================================================================
--- SplashOutputDev.cc	(revision 23)
+++ SplashOutputDev.cc	(working copy)
@@ -947,7 +947,7 @@
   GfxFontType fontType;
   SplashOutFontFileID *id;
   SplashFontFile *fontFile;
-  SplashFontSrc *fontsrc;
+  SplashFontSrc *fontsrc = NULL;
   FoFiTrueType *ff;
   Ref embRef;
   Object refObj, strObj;
@@ -1022,7 +1022,7 @@
     if (fileName)
       fontsrc->setFile(fileName, gFalse);
     else
-      fontsrc->setBuf(tmpBuf, tmpBufLen, gFalse);
+      fontsrc->setBuf(tmpBuf, tmpBufLen, gTrue);
 
     // load the font file
     switch (fontType) {
@@ -1170,11 +1170,15 @@
   }
   font = fontEngine->getFont(fontFile, mat);
 
+  if (fontsrc)
+      fontsrc->unref();
   return;
 
  err2:
   delete id;
  err1:
+  if (fontsrc)
+      fontsrc->unref();
   return;
 }
 


More information about the poppler mailing list