Ilya Zakharevich on Thu, 10 Sep 1998 01:05:27 -0400 (EDT)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Tmpfile leak


This patch allows pari use the standard TMP directory, and fixes a
leak of a TMP file (probably fixed already - mpqs_close() chunk).  All
the err() patches are cosmetic only.

The __EMX__ chunk should probably be generalized to DOSISH, but I do
not know in which header file to define this macro.

Enjoy,
Ilya

--- ./src/language/es.c~	Thu Jul 23 13:13:06 1998
+++ ./src/language/es.c	Wed Sep  9 22:11:50 1998
@@ -2037,6 +2037,13 @@ pari_tmp_dir()
 {
 #ifndef macintosh
   char *s = getenv("GPTMPDIR");
+
+#ifdef __EMX__
+  if (!s)
+      s = getenv("TMP");
+  if (!s)
+      s = getenv("TEMP");
+#endif
   if (s)
   {
     if (pari_is_rwxdir(s)) return s;
--- ./src/modules/mpqs.c~	Wed Jul 29 17:30:04 1998
+++ ./src/modules/mpqs.c	Wed Sep  9 22:20:34 1998
@@ -136,14 +136,14 @@ static void
 mpqs_close_file(FILE *fp)
 {
   if (fclose(fp))
-    err(warner, "error trying to close temporary file");
+    err(warner, "error trying to close temporary file: %s", strerror(errno));
 }
 
 static void
 mpqs_unlink(char *f)
 {
   if (unlink(f))
-    err(warner, "can\'t remove file %s", f);
+    err(warner, "can\'t remove file %s: %s", f, strerror(errno));
 }
 
 /**
@@ -506,6 +506,7 @@ mpqs_mergesort_lp_file(FILE *LPREL, FILE
       }
     } /* while */
     if (COMB) mpqs_close_file(COMB);
+    mpqs_close_file(TMP);
     return i;
   }
 
@@ -2467,12 +2468,12 @@ mpqs_get_relation(long pos, FILE *fp)
   {
     mpqs_close_file(fp);
     /* may also fail, but we're giving up anyway... GN */
-    err(talker, "can\'t seek relations file");
+    err(talker, "can\'t seek relations file: %s", strerror(errno));
   }
   if (fgets(buf, MPQS_STRING_LENGTH, fp) == NULL)
   {
     mpqs_close_file(fp);
-    err(talker, "relations file truncated?!");
+    err(talker, "relations file truncated?! (%s)", strerror(errno));
   }
   return buf;
 }
@@ -3396,7 +3397,8 @@ mpqs(GEN N)
 
     mpqs_unlink(LPREL_str);
     if (rename(LPTMP_str, LPREL_str))
-      err(talker, "can\'t rename file %s to %s", LPTMP_str, LPREL_str);
+      err(talker, "can\'t rename file %s to %s: %s", 
+	  LPTMP_str, LPREL_str, strerror(errno));
     LPNEW = mpqs_open_file(LPNEW_str, "w");
 
     /* combine whatever there is to be combined */
@@ -3449,7 +3451,8 @@ mpqs(GEN N)
 
     mpqs_unlink(FREL_str);
     if (rename(LPTMP_str, FREL_str))
-      err(talker, "can\'t rename file %s to %s", LPTMP_str, FREL_str);
+      err(talker, "can\'t rename file %s to %s: %s", 
+	  LPTMP_str, FREL_str, strerror(errno));
     /* FNEW stays closed until we know whether we need to reopen it for
        another iteration */