diff -ur dvipdfmx-20120420.orig/src/cid.c dvipdfmx-20120420/src/cid.c
--- dvipdfmx-20120420.orig/src/cid.c	2011-03-07 18:11:26.000000000 +0100
+++ dvipdfmx-20120420/src/cid.c	2012-04-27 13:35:25.000000000 +0200
@@ -70,7 +70,7 @@
   {"Adobe", "Japan1",   {-1, -1, 2, 2, 4, 5, 6, 6}},
   {"Adobe", "Korea1",   {-1, -1, 1, 1, 2, 2, 2, 2}},
   {"Adobe", "Identity", {-1, -1, 0, 0, 0, 0, 0, 0}},
-  {NULL, NULL, {0,0,0,0,0,0,0,0}}
+  {NULL,    NULL,       { 0,  0, 0, 0, 0, 0, 0, 0}}
 };
 #define UCS_CC    0
 #define ACC_START 1
diff -ur dvipdfmx-20120420.orig/src/cidtype0.c dvipdfmx-20120420/src/cidtype0.c
--- dvipdfmx-20120420.orig/src/cidtype0.c	2011-03-07 18:11:26.000000000 +0100
+++ dvipdfmx-20120420/src/cidtype0.c	2012-04-27 13:33:11.000000000 +0200
@@ -467,7 +467,7 @@
 {
   sfnt     *sfont;
   cff_font *cffont;
-  FILE     *fp;
+  FILE     *fp = NULL;
   cff_index    *charstrings, *idx;
   cff_charsets *charset = NULL;
   cff_fdselect *fdselect = NULL;
@@ -571,7 +571,8 @@
     RELEASE(CIDToGIDMap);
     cff_close(cffont);
     sfnt_close(sfont);
-    DPXFCLOSE(fp);
+    if (fp)
+      DPXFCLOSE(fp);
 
     return;
   }
@@ -689,7 +690,8 @@
 
   cff_close(cffont);
   sfnt_close(sfont);
-  DPXFCLOSE(fp);
+  if (fp)
+    DPXFCLOSE(fp);
 
   if (verbose > 1)
     MESG("[%u/%u glyphs][%ld bytes]", num_glyphs, cs_count, destlen);
@@ -719,7 +721,7 @@
   char       *fontname;
   sfnt       *sfont;
   cff_font   *cffont;
-  FILE       *fp;
+  FILE       *fp = NULL;
   unsigned long offset = 0;
 
   ASSERT(font);
@@ -746,7 +748,8 @@
   if (!(cffont->flag & FONTTYPE_CIDFONT)) {
     cff_close(cffont);
     sfnt_close(sfont);
-    DPXFCLOSE(fp);
+    if (fp)
+      DPXFCLOSE(fp);
     return -1;
   }
 
@@ -819,7 +822,7 @@
   /* getting font info. from TrueType tables */
   if ((font->descriptor
        = tt_get_fontdesc(sfont, &(opt->embed), opt->stemv, 0)) == NULL)
-    ERROR("Could not obtain neccesary font info.");
+    ERROR("Could not obtain necessary font info.");
 
   if (opt->embed) {
     memmove(fontname + 7, fontname, strlen(fontname) + 1);
@@ -851,7 +854,8 @@
 	       pdf_new_number(1000)); /* not sure */
 
   sfnt_close(sfont);
-  DPXFCLOSE(fp);
+  if (fp)
+    DPXFCLOSE(fp);
 
   return 0;
 }
@@ -871,7 +875,7 @@
   int    parent_id;
   char  *used_chars;
   double default_width, nominal_width;
-  FILE  *fp;
+  FILE  *fp = NULL;
 
   ASSERT(font);
 
@@ -1102,7 +1106,8 @@
   }
 
   sfnt_close(sfont);
-  DPXFCLOSE(fp);
+  if (fp)
+    DPXFCLOSE(fp);
 
   if (verbose > 1)
     MESG("[%u glyphs][%ld bytes]", num_glyphs, destlen);
@@ -1133,7 +1138,7 @@
   sfnt       *sfont;
   cff_font   *cffont;
   unsigned long offset = 0;
-  FILE       *fp;
+  FILE       *fp = NULL;
 
   ASSERT(font);
 
@@ -1159,7 +1164,8 @@
   if (cffont->flag & FONTTYPE_CIDFONT) {
     cff_close(cffont);
     sfnt_close(sfont);
-    DPXFCLOSE(fp);
+    if (fp)
+      DPXFCLOSE(fp);
 
     return -1;
   }
@@ -1218,7 +1224,7 @@
   /* getting font info. from TrueType tables */
   if ((font->descriptor
        = tt_get_fontdesc(sfont, &(opt->embed), opt->stemv, 0)) == NULL)
-    ERROR("Could not obtain neccesary font info.");
+    ERROR("Could not obtain necessary font info.");
 
   if (opt->embed) {
     memmove(fontname + 7, fontname, strlen(fontname) + 1);
@@ -1246,7 +1252,8 @@
     pdf_add_dict(font->fontdict, pdf_new_name("CIDSystemInfo"), csi_dict);
   }
   sfnt_close(sfont);
-  DPXFCLOSE(fp);
+  if (fp)
+    DPXFCLOSE(fp);
 
   return 0;
 }
@@ -1372,11 +1379,9 @@
     return -1;
 
   cffont = t1_load_font(NULL, 1, fp);
-  if (!cffont) {
-    DPXFCLOSE(fp);
-    return -1;
-  }
   DPXFCLOSE(fp);
+  if (!cffont)
+    return -1;
 
   cmap_id = load_base_CMap(font_name, wmode, cffont);
   
diff -ur dvipdfmx-20120420.orig/src/cidtype2.c dvipdfmx-20120420/src/cidtype2.c
--- dvipdfmx-20120420.orig/src/cidtype2.c	2011-03-07 18:11:26.000000000 +0100
+++ dvipdfmx-20120420/src/cidtype2.c	2012-04-27 13:42:54.000000000 +0200
@@ -498,7 +498,7 @@
   unsigned char *cidtogidmap;
   USHORT   num_glyphs;
   int      i, glyph_ordering = 0, unicode_cmap = 0;
-  FILE    *fp;
+  FILE    *fp = NULL;
 
   if (!font->indirect)
     return;
@@ -853,7 +853,8 @@
     if (cidtogidmap)
       RELEASE(cidtogidmap);
     sfnt_close(sfont);
-    DPXFCLOSE(fp);
+    if (fp)
+      DPXFCLOSE(fp);
 
     return;
   }
@@ -873,7 +874,8 @@
   fontfile = sfnt_create_FontFile_stream(sfont);
 
   sfnt_close(sfont);
-  DPXFCLOSE(fp);
+  if (fp)
+    DPXFCLOSE(fp);
 
   if (!fontfile)
     ERROR("Could not created FontFile stream for \"%s\".", font->ident);
@@ -926,7 +928,7 @@
   char    *fontname;
   sfnt    *sfont;
   unsigned long offset = 0;
-  FILE    *fp;
+  FILE    *fp = NULL;
 
   ASSERT(font && opt);
 
@@ -960,7 +962,8 @@
     break;
   default:
     sfnt_close(sfont);
-    DPXFCLOSE(fp);
+    if (fp)
+      DPXFCLOSE(fp);
     return -1;
     break;
   }
@@ -1059,7 +1062,7 @@
 
   font->descriptor = tt_get_fontdesc(sfont, &(opt->embed), opt->stemv, 0);
   if (!font->descriptor) {
-    ERROR("Could not obtain neccesary font info.");
+    ERROR("Could not obtain necessary font info.");
   }
 
   if (opt->embed) {
@@ -1076,7 +1079,8 @@
 	       pdf_new_name(fontname));
 
   sfnt_close(sfont);
-  DPXFCLOSE(fp);
+  if (fp)
+    DPXFCLOSE(fp);
 
   /*
    * Don't write fontdict here.
diff -ur dvipdfmx-20120420.orig/src/truetype.c dvipdfmx-20120420/src/truetype.c
--- dvipdfmx-20120420.orig/src/truetype.c	2011-03-07 18:11:26.000000000 +0100
+++ dvipdfmx-20120420/src/truetype.c	2012-04-27 14:28:16.000000000 +0200
@@ -68,7 +68,7 @@
   pdf_obj  *fontdict, *descriptor;
   sfnt     *sfont;
   int       embedding = 1; /* Must be embedded. */
-  FILE     *fp;
+  FILE     *fp = NULL;
   int       length, error = 0;
 
   ASSERT( font );
@@ -89,7 +89,8 @@
 
   if (!sfont) {
     WARN("Could not open TrueType font: %s", ident);
-    DPXFCLOSE(fp);
+    if (fp)
+      DPXFCLOSE(fp);
     return  -1;
   }
 
@@ -104,7 +105,8 @@
 
   if (error) {
     sfnt_close(sfont);
-    DPXFCLOSE(fp);
+    if (fp)
+      DPXFCLOSE(fp);
     return  -1; /* Silently */
   }
 
@@ -124,9 +126,10 @@
     pdf_obj  *tmp;
     tmp  = tt_get_fontdesc(sfont, &embedding, -1, 1);
     if (!tmp) {
-      ERROR("Could not obtain neccesary font info.");
+      ERROR("Could not obtain necessary font info.");
       sfnt_close(sfont);
-      DPXFCLOSE(fp);
+      if (fp)
+        DPXFCLOSE(fp);
       return  -1;
     }
     ASSERT(pdf_obj_typeof(tmp) == PDF_DICT);
@@ -189,7 +192,8 @@
   }
 
   sfnt_close(sfont);
-  DPXFCLOSE(fp);
+  if (fp)
+    DPXFCLOSE(fp);
 
   pdf_add_dict(fontdict,
                pdf_new_name("Type"),    pdf_new_name("Font"));
@@ -882,7 +886,7 @@
   int        index       = pdf_font_get_index(font);
   char     **enc_vec;
   pdf_obj   *fontfile;
-  FILE      *fp;
+  FILE      *fp = NULL;
   sfnt      *sfont;
   int        i, error = 0;
 
@@ -902,14 +906,16 @@
 
   if (!sfont) {
     ERROR("Unable to open TrueType/dfont file: %s", ident);
-    DPXFCLOSE(fp);
+    if (fp)
+      DPXFCLOSE(fp);
     return  -1;
   } else if (sfont->type != SFNT_TYPE_TRUETYPE &&
              sfont->type != SFNT_TYPE_TTC &&
              sfont->type != SFNT_TYPE_DFONT) { 
     ERROR("Font \"%s\" not a TrueType/dfont font?", ident);
     sfnt_close(sfont);
-    DPXFCLOSE(fp);
+    if (fp)
+      DPXFCLOSE(fp);
     return  -1;
   }
 
@@ -925,7 +931,8 @@
   if (error) {
     ERROR("Reading SFND table dir failed for font-file=\"%s\"... Not a TrueType font?", ident);
     sfnt_close(sfont);
-    DPXFCLOSE(fp);
+    if (fp)
+      DPXFCLOSE(fp);
     return  -1;
   }
 
@@ -941,14 +948,16 @@
   if (error) {
     ERROR("Error occured while creating font subfont for \"%s\"", ident);
     sfnt_close(sfont);
-    DPXFCLOSE(fp);
+    if (fp)
+      DPXFCLOSE(fp);
     return  -1;
   }
 
 #if  ENABLE_NOEMBED
   if (!embedding) {
     sfnt_close(sfont);
-    DPXFCLOSE(fp);
+    if (fp)
+      DPXFCLOSE(fp);
     return  0;
   }
 #endif /* ENABLE_NOEMBED */
@@ -964,7 +973,8 @@
       ERROR("Required TrueType table \"%s\" does not exist in font: %s",
             required_table[i].name, ident);
       sfnt_close(sfont);
-      DPXFCLOSE(fp);
+      if (fp)
+        DPXFCLOSE(fp);
       return  -1;
     }
   }
@@ -977,7 +987,8 @@
     ERROR("Could not created FontFile stream for \"%s\".", ident);
 
   sfnt_close(sfont);
-  DPXFCLOSE(fp);
+  if (fp)
+    DPXFCLOSE(fp);
 
   if (verbose > 1)
     MESG("[%ld bytes]", pdf_stream_length(fontfile));
diff -ur dvipdfmx-20120420.orig/src/tt_cmap.c dvipdfmx-20120420/src/tt_cmap.c
--- dvipdfmx-20120420.orig/src/tt_cmap.c	2011-10-19 09:10:39.000000000 +0200
+++ dvipdfmx-20120420/src/tt_cmap.c	2012-04-27 14:46:54.000000000 +0200
@@ -1029,7 +1029,7 @@
   int         cmap_add_id;
   tt_cmap    *ttcmap;
   char       *cmap_name;
-  FILE       *fp;
+  FILE       *fp = NULL;
   sfnt       *sfont;
   long        offset = 0;
 
@@ -1124,7 +1124,8 @@
   RELEASE(cmap_name);
 
   sfnt_close(sfont);
-  DPXFCLOSE(fp);
+  if (fp)
+    DPXFCLOSE(fp);
 
   return cmap_ref;
 }
@@ -1601,7 +1602,7 @@
   unsigned long   offset = 0;
   char  *base_name = NULL, *cmap_name = NULL;
   char  *tounicode_name = NULL;
-  FILE  *fp;
+  FILE  *fp = NULL;
   otl_gsub      *gsub_list = NULL;
   tt_cmap       *ttcmap;
   CMap          *cmap, *base, *tounicode = NULL;
diff -ur dvipdfmx-20120420.orig/src/type1c.c dvipdfmx-20120420/src/type1c.c
--- dvipdfmx-20120420.orig/src/type1c.c	2010-04-05 02:34:08.000000000 +0200
+++ dvipdfmx-20120420/src/type1c.c	2012-04-27 14:34:55.000000000 +0200
@@ -70,7 +70,7 @@
 pdf_font_open_type1c (pdf_font *font)
 {
   char     *ident, *fontname;
-  FILE     *fp;
+  FILE     *fp = NULL;
   sfnt     *sfont;
   cff_font *cffont;
   pdf_obj  *descriptor, *tmp;
@@ -106,7 +106,8 @@
   if (cffont->flag & FONTTYPE_CIDFONT) {
     cff_close (cffont);
     sfnt_close(sfont);
-    DPXFCLOSE(fp);
+    if (fp)
+      DPXFCLOSE(fp);
     return -1;
   }
 
@@ -149,7 +150,8 @@
   }
 
   sfnt_close(sfont);
-  DPXFCLOSE(fp);
+  if (fp)
+    DPXFCLOSE(fp);
 
   return 0;
 }
@@ -230,7 +232,7 @@
   pdf_obj      *fontdict, *descriptor;
   char         *usedchars;
   char         *fontname, *uniqueTag, *ident, *fullname;
-  FILE         *fp;
+  FILE         *fp = NULL;
   int           encoding_id;
   pdf_obj      *fontfile, *stream_dict;
   char        **enc_vec;
@@ -708,7 +710,8 @@
   cff_close (cffont);
   sfnt_close(sfont);
 
-  DPXFCLOSE(fp);
+  if (fp)
+    DPXFCLOSE(fp);
 
   if (verbose > 1) {
     MESG("[%u/%u glyphs][%ld bytes]", num_glyphs, cs_count, offset);
