Description: remove more hardcoded predictable paths in /tmp
 Remove some more problematic temporary filenames.
 .
Author: Jeff Breidenbach <jab@debian.org>
Bug-Debian: http://bugs.debian.org/830660

--- leptonlib-1.73.orig/src/psio1.c
+++ leptonlib-1.73/src/psio1.c
@@ -728,8 +728,7 @@ pixWriteMixedToPS(PIX         *pixb,
                   l_int32      pageno,
                   const char  *fileout)
 {
-const char   tnameb[] = "/tmp/lept/psio/mixed.tif";
-const char   tnamec[] = "/tmp/lept/psio/mixed.jpg";
+char        *tname;
 const char  *op;
 l_int32      resb, resc, endpage, maskop, ret;
 
@@ -750,13 +749,15 @@ l_int32      resb, resc, endpage, maskop
     }
 
         /* Write the jpeg image first */
-    lept_mkdir("lept/psio");
     if (pixc) {
-        pixWrite(tnamec, pixc, IFF_JFIF_JPEG);
+        tname = genTempFilename("/tmp", "mixed.jpg", 1, 1);
+        pixWrite(tname, pixc, IFF_JFIF_JPEG);
         endpage = (pixb) ? FALSE : TRUE;
         op = (pageno <= 1) ? "w" : "a";
-        ret = convertJpegToPS(tnamec, fileout, op, 0, 0, resc, 1.0,
+        ret = convertJpegToPS(tname, fileout, op, 0, 0, resc, 1.0,
                               pageno, endpage);
+        lept_rmfile(tname);
+        LEPT_FREE(tname);
         if (ret)
             return ERROR_INT("jpeg data not written", procName, 1);
     }
@@ -764,11 +765,14 @@ l_int32      resb, resc, endpage, maskop
         /* Write the binary data, either directly or, if there is
          * a jpeg image on the page, through the mask. */
     if (pixb) {
-        pixWrite(tnameb, pixb, IFF_TIFF_G4);
+        tname = genTempFilename("/tmp", "mixed.tif", 1, 1);
+        pixWrite(tname, pixb, IFF_TIFF_G4);
         op = (pageno <= 1 && !pixc) ? "w" : "a";
         maskop = (pixc) ? 1 : 0;
-        ret = convertG4ToPS(tnameb, fileout, op, 0, 0, resb, 1.0,
+        ret = convertG4ToPS(tname, fileout, op, 0, 0, resb, 1.0,
                             pageno, maskop, 1);
+        lept_rmfile(tname);
+        LEPT_FREE(tname);
         if (ret)
             return ERROR_INT("tiff data not written", procName, 1);
     }
@@ -807,10 +811,9 @@ convertToPSEmbed(const char  *filein,
                  const char  *fileout,
                  l_int32      level)
 {
-const char  nametif[] = "/tmp/junk_convert_ps_embed.tif";
-const char  namejpg[] = "/tmp/junk_convert_ps_embed.jpg";
-l_int32     d, format;
-PIX        *pix, *pixs;
+char    *tname;
+l_int32  d, format;
+PIX     *pix, *pixs;
 
     PROCNAME("convertToPSEmbed");
 
@@ -859,14 +862,17 @@ PIX        *pix, *pixs;
         pix = pixRemoveColormap(pixs, REMOVE_CMAP_BASED_ON_SRC);
 
     d = pixGetDepth(pix);
+    tname = genTempFilename("/tmp", "embed", 1, 1);
     if (d == 1) {
-        pixWrite(nametif, pix, IFF_TIFF_G4);
-        convertG4ToPSEmbed(nametif, fileout);
+        pixWrite(tname, pix, IFF_TIFF_G4);
+        convertG4ToPSEmbed(tname, fileout);
     } else {
-        pixWrite(namejpg, pix, IFF_JFIF_JPEG);
-        convertJpegToPSEmbed(namejpg, fileout);
+        pixWrite(tname, pix, IFF_JFIF_JPEG);
+        convertJpegToPSEmbed(tname, fileout);
     }
 
+    lept_rmfile(tname);
+    LEPT_FREE(tname);
     pixDestroy(&pix);
     pixDestroy(&pixs);
     return 0;
@@ -905,7 +911,7 @@ pixaWriteCompressedToPS(PIXA        *pix
                         l_int32      res,
                         l_int32      level)
 {
-char     *tname, *g4_name, *jpeg_name, *png_name;
+char     *tname;
 l_int32   i, n, firstfile, index, writeout, d;
 PIX      *pix, *pixt;
 PIXCMAP  *cmap;
@@ -924,45 +930,35 @@ PIXCMAP  *cmap;
     n = pixaGetCount(pixa);
     firstfile = TRUE;
     index = 0;
-    lept_mkdir("lept/comp");
-    g4_name = genTempFilename("/tmp/lept/comp", "temp.tif", 0, 0);
-    jpeg_name = genTempFilename("/tmp/lept/comp", "temp.jpg", 0, 0);
-    png_name = genTempFilename("/tmp/lept/comp", "temp.png", 0, 0);
+    tname = genTempFilename("/tmp", "temp", 0, 0);
     for (i = 0; i < n; i++) {
         writeout = TRUE;
         pix = pixaGetPix(pixa, i, L_CLONE);
         d = pixGetDepth(pix);
         cmap = pixGetColormap(pix);
         if (d == 1) {
-            tname = g4_name;
             pixWrite(tname, pix, IFF_TIFF_G4);
         } else if (cmap) {
             if (level == 2) {
                 pixt = pixConvertForPSWrap(pix);
-                tname = jpeg_name;
                 pixWrite(tname, pixt, IFF_JFIF_JPEG);
                 pixDestroy(&pixt);
             } else {  /* level == 3 */
-                tname = png_name;
                 pixWrite(tname, pix, IFF_PNG);
             }
         } else if (d == 16) {
             if (level == 2)
                 L_WARNING("d = 16; must write out flate\n", procName);
-            tname = png_name;
             pixWrite(tname, pix, IFF_PNG);
         } else if (d == 2 || d == 4) {
             if (level == 2) {
                 pixt = pixConvertTo8(pix, 0);
-                tname = jpeg_name;
                 pixWrite(tname, pixt, IFF_JFIF_JPEG);
                 pixDestroy(&pixt);
             } else {  /* level == 3 */
-                tname = png_name;
                 pixWrite(tname, pix, IFF_PNG);
             }
         } else if (d == 8 || d == 32) {
-            tname = jpeg_name;
             pixWrite(tname, pix, IFF_JFIF_JPEG);
         } else {  /* shouldn't happen */
             L_ERROR("invalid depth: %d\n", procName, d);
@@ -975,9 +971,8 @@ PIXCMAP  *cmap;
                                          &firstfile, &index);
     }
 
-    LEPT_FREE(g4_name);
-    LEPT_FREE(jpeg_name);
-    LEPT_FREE(png_name);
+    lept_rmfile(tname);
+    LEPT_FREE(tname);
     return 0;
 }
 
--- leptonlib-1.73.orig/src/psio2.c
+++ leptonlib-1.73/src/psio2.c
@@ -1382,8 +1382,7 @@ SARRAY  *sa;
  *
  *      Input:  filein (input tiff multipage file)
  *              fileout (output ps file)
- *              tempfile (<optional> for temporary g4 tiffs;
- *                        use NULL for default)
+ *              tempfile Deprecated. Set to NULL.
  *              factor (for filling 8.5 x 11 inch page;
  *                      use 0.0 for DEFAULT_FILL_FRACTION)
  *      Return: 0 if OK, 1 on error
@@ -1401,7 +1400,6 @@ convertTiffMultipageToPS(const char  *fi
                          const char  *tempfile,
                          l_float32    fillfract)
 {
-const char   tempdefault[] = "/tmp/junk_temp_g4.tif";
 const char  *tempname;
 l_int32      i, npages, w, h, istiff;
 l_float32    scale;
@@ -1425,20 +1423,19 @@ FILE        *fp;
     tiffGetCount(fp, &npages);
     fclose(fp);
 
-    if (tempfile)
-        tempname = tempfile;
-    else
-        tempname = tempdefault;
+    tempname = genTempFilename("/tmp", "tfile", 1, 1);
 
     if (fillfract == 0.0)
         fillfract = DEFAULT_FILL_FRACTION;
 
     for (i = 0; i < npages; i++) {
-        if ((pix = pixReadTiff(filein, i)) == NULL)
-             return ERROR_INT("pix not made", procName, 1);
+        if ((pix = pixReadTiff(filein, i)) == NULL) {
+            lept_rmfile(tempname);
+            LEPT_FREE(tempname);
+            return ERROR_INT("pix not made", procName, 1);
+        }
 
-        w = pixGetWidth(pix);
-        h = pixGetHeight(pix);
+        pixGetDimensions(pix, &w, &h, NULL);
         if (w == 1728 && h < w)   /* it's a std res fax */
             pixs = pixScale(pix, 1.0, 2.0);
         else
@@ -1456,6 +1453,9 @@ FILE        *fp;
         pixDestroy(&pixs);
     }
 
+    lept_rmfile(tempname);
+    LEPT_FREE(tempname);
+
     return 0;
 }
 
