Move the const_cast from assignment to free

The problem is that some of the times the pointers hold values
to const tables and some others hold values to dynamic memory.

Instead of const_casting the const tables when needed and holding a non
const pointer, we hold a const pointer and only const cast on free if
needed
diff --git a/fofi/FoFiType1C.cc b/fofi/FoFiType1C.cc
index 8ecc066..cdcef18 100644
--- a/fofi/FoFiType1C.cc
+++ b/fofi/FoFiType1C.cc
@@ -107,7 +107,7 @@
       charset != fofiType1CISOAdobeCharset &&
       charset != fofiType1CExpertCharset &&
       charset != fofiType1CExpertSubsetCharset) {
-    gfree(charset);
+    gfree(const_cast<unsigned short *>(charset));
   }
 }
 
@@ -2503,25 +2503,25 @@
   int nLeft, i, j;
 
   if (topDict.charsetOffset == 0) {
-    charset = const_cast<unsigned short*>(fofiType1CISOAdobeCharset);
+    charset = fofiType1CISOAdobeCharset;
     charsetLength = sizeof(fofiType1CISOAdobeCharset) / sizeof(unsigned short);
   } else if (topDict.charsetOffset == 1) {
-    charset = const_cast<unsigned short*>(fofiType1CExpertCharset);
+    charset = fofiType1CExpertCharset;
     charsetLength = sizeof(fofiType1CExpertCharset) / sizeof(unsigned short);
   } else if (topDict.charsetOffset == 2) {
-    charset = const_cast<unsigned short*>(fofiType1CExpertSubsetCharset);
+    charset = fofiType1CExpertSubsetCharset;
     charsetLength = sizeof(fofiType1CExpertSubsetCharset) / sizeof(unsigned short);
   } else {
-    charset = (unsigned short *)gmallocn(nGlyphs, sizeof(unsigned short));
+    unsigned short *customCharset = (unsigned short *)gmallocn(nGlyphs, sizeof(unsigned short));
     charsetLength = nGlyphs;
     for (i = 0; i < nGlyphs; ++i) {
-      charset[i] = 0;
+      customCharset[i] = 0;
     }
     pos = topDict.charsetOffset;
     charsetFormat = getU8(pos++, &parsedOk);
     if (charsetFormat == 0) {
       for (i = 1; i < nGlyphs; ++i) {
-	charset[i] = (unsigned short)getU16BE(pos, &parsedOk);
+	customCharset[i] = (unsigned short)getU16BE(pos, &parsedOk);
 	pos += 2;
 	if (!parsedOk) {
 	  break;
@@ -2537,7 +2537,7 @@
 	  break;
 	}
 	for (j = 0; j <= nLeft && i < nGlyphs; ++j) {
-	  charset[i++] = (unsigned short)c++;
+	  customCharset[i++] = (unsigned short)c++;
 	}
       }
     } else if (charsetFormat == 2) {
@@ -2551,16 +2551,17 @@
 	  break;
 	}
 	for (j = 0; j <= nLeft && i < nGlyphs; ++j) {
-	  charset[i++] = (unsigned short)c++;
+	  customCharset[i++] = (unsigned short)c++;
 	}
       }
     }
     if (!parsedOk) {
-      gfree(charset);
+      gfree(customCharset);
       charset = nullptr;
       charsetLength = 0;
       return false;
     }
+    charset = customCharset;
   }
   return true;
 }
diff --git a/fofi/FoFiType1C.h b/fofi/FoFiType1C.h
index faae806..ff69651 100644
--- a/fofi/FoFiType1C.h
+++ b/fofi/FoFiType1C.h
@@ -246,7 +246,7 @@
   int nGlyphs;
   int nFDs;
   unsigned char *fdSelect;
-  unsigned short *charset;
+  const unsigned short *charset;
   unsigned short charsetLength;
   int gsubrBias;
 
diff --git a/poppler/UnicodeMap.cc b/poppler/UnicodeMap.cc
index 6125294..6e7e467 100644
--- a/poppler/UnicodeMap.cc
+++ b/poppler/UnicodeMap.cc
@@ -14,7 +14,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2010 Jakub Wilk <jwilk@jwilk.net>
-// Copyright (C) 2017, 2018 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2017-2019 Albert Astals Cid <aacid@kde.org>
 // Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
 // Copyright (C) 2017 Jean Ghali <jghali@libertysurf.fr>
 // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
@@ -71,7 +71,7 @@
   map = new UnicodeMap(encodingNameA->copy());
 
   size = 8;
-  map->ranges = (UnicodeMapRange *)gmallocn(size, sizeof(UnicodeMapRange));
+  UnicodeMapRange *customRanges = (UnicodeMapRange *)gmallocn(size, sizeof(UnicodeMapRange));
   eMapsSize = 0;
 
   line = 1;
@@ -86,10 +86,10 @@
       if (nBytes <= 4) {
 	if (map->len == size) {
 	  size *= 2;
-	  map->ranges = (UnicodeMapRange *)
-	    greallocn(map->ranges, size, sizeof(UnicodeMapRange));
+	  customRanges = (UnicodeMapRange *)
+	    greallocn(customRanges, size, sizeof(UnicodeMapRange));
 	}
-	range = &map->ranges[map->len];
+	range = &customRanges[map->len];
 	sscanf(tok1, "%x", &range->start);
 	sscanf(tok2, "%x", &range->end);
 	sscanf(tok3, "%x", &range->code);
@@ -125,6 +125,7 @@
 
   fclose(f);
 
+  map->ranges = customRanges;
   return map;
 }
 
@@ -144,7 +145,7 @@
   encodingName = new GooString(encodingNameA);
   unicodeOut = unicodeOutA;
   kind = unicodeMapResident;
-  ranges = const_cast<UnicodeMapRange*>(rangesA);
+  ranges = rangesA;
   len = lenA;
   eMaps = nullptr;
   eMapsLen = 0;
@@ -165,7 +166,7 @@
 UnicodeMap::~UnicodeMap() {
   delete encodingName;
   if (kind == unicodeMapUser && ranges) {
-    gfree(ranges);
+    gfree(const_cast<UnicodeMapRange *>(ranges));
   }
   if (eMaps) {
     gfree(eMaps);
diff --git a/poppler/UnicodeMap.h b/poppler/UnicodeMap.h
index 74f6ded..17f1d59 100644
--- a/poppler/UnicodeMap.h
+++ b/poppler/UnicodeMap.h
@@ -16,7 +16,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
-// Copyright (C) 2018 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2018, 2019 Albert Astals Cid <aacid@kde.org>
 // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
 // Copyright (C) 2019 Volker Krause <vkrause@kde.org>
 //
@@ -104,7 +104,7 @@
   UnicodeMapKind kind;
   bool unicodeOut;
   union {
-    UnicodeMapRange *ranges;	// (user, resident)
+    const UnicodeMapRange *ranges;	// (user, resident)
     UnicodeMapFunc func;	// (func)
   };
   int len;			// (user, resident)