[poppler] poppler/Gfx.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Mon Jul 31 23:14:46 UTC 2017


 poppler/Gfx.cc |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

New commits:
commit e5ff049c3d11e6ea24b624807730acd21a6ef4d5
Author: Albert Astals Cid <aacid at kde.org>
Date:   Tue Aug 1 01:07:00 2017 +0200

    Gfx::doImage: Simplify memory management
    
    of maskColorMap by using a std::unique_ptr
    
    Fixes a memory leak reported by Coverity

diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index 4a9aab5c..be9810e1 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -55,6 +55,7 @@
 #include <stddef.h>
 #include <string.h>
 #include <math.h>
+#include <memory>
 #include "goo/gmem.h"
 #include "goo/GooTimer.h"
 #include "goo/GooHash.h"
@@ -4175,7 +4176,6 @@ void Gfx::doImage(Object *ref, Stream *str, GBool inlineImg) {
   GBool mask;
   GBool invert;
   GfxColorSpace *colorSpace, *maskColorSpace;
-  GfxImageColorMap *maskColorMap;
   GBool haveColorKeyMask, haveExplicitMask, haveSoftMask;
   int maskColors[2*gfxColorMaxComps];
   int maskWidth, maskHeight;
@@ -4374,7 +4374,7 @@ void Gfx::doImage(Object *ref, Stream *str, GBool inlineImg) {
     maskStr = NULL; // make gcc happy
     maskWidth = maskHeight = 0; // make gcc happy
     maskInvert = gFalse; // make gcc happy
-    maskColorMap = NULL; // make gcc happy
+    std::unique_ptr<GfxImageColorMap> maskColorMap;
     Object maskObj = dict->lookup("Mask");
     Object smaskObj = dict->lookup("SMask");
     if (smaskObj.isStream()) {
@@ -4434,9 +4434,8 @@ void Gfx::doImage(Object *ref, Stream *str, GBool inlineImg) {
       if (obj1.isNull()) {
 	obj1 = maskDict->lookup("D");
       }
-      maskColorMap = new GfxImageColorMap(maskBits, &obj1, maskColorSpace);
+      maskColorMap.reset(new GfxImageColorMap(maskBits, &obj1, maskColorSpace));
       if (!maskColorMap->isOk()) {
-	delete maskColorMap;
 	goto err1;
       }
       // handle the Matte entry
@@ -4552,8 +4551,7 @@ void Gfx::doImage(Object *ref, Stream *str, GBool inlineImg) {
     } else {
       if (haveSoftMask) {
 	out->drawSoftMaskedImage(state, ref, str, width, height, &colorMap, interpolate,
-				 maskStr, maskWidth, maskHeight, maskColorMap, maskInterpolate);
-	delete maskColorMap;
+				 maskStr, maskWidth, maskHeight, maskColorMap.get(), maskInterpolate);
       } else if (haveExplicitMask) {
 	out->drawMaskedImage(state, ref, str, width, height, &colorMap, interpolate,
 			     maskStr, maskWidth, maskHeight, maskInvert, maskInterpolate);


More information about the poppler mailing list