Просмотр исходного кода

* Bugs all around in the tempfile class regarding closing, fixed all of them.

svn: 2055
Bryan Drewery 21 лет назад
Родитель
Сommit
29240528f4
4 измененных файлов с 18 добавлено и 5 удалено
  1. 3 1
      src/binary.c
  2. 2 0
      src/conf.c
  3. 12 4
      src/misc_file.c
  4. 1 0
      src/misc_file.h

+ 3 - 1
src/binary.c

@@ -73,6 +73,7 @@ bin_checksum(const char *fname, int todo)
     }
 
     fclose(f);
+    f = NULL;
     MD5_Final(md5out, &ctx);
     strlcpy(hash, btoh(md5out, MD5_DIGEST_LENGTH), sizeof(hash));
     OPENSSL_cleanse(&ctx, sizeof(ctx));
@@ -176,7 +177,8 @@ bin_checksum(const char *fname, int todo)
     }
 
     fclose(f);
-    fclose(newbin->f);
+    f = NULL;
+    newbin->my_close();
 
     if (size != newpos) {
       delete newbin;

+ 2 - 0
src/conf.c

@@ -269,6 +269,8 @@ confedit()
   if (conf.bots && conf.bots->pid)
     localhub_pid = conf.bots->pid;
 
+  tmpconf.my_close();
+
   readconf((const char *) tmpconf.file, 0);               /* read cleartext conf tmp into &settings */
   fix_tilde(&conf.binpath);
   unlink(tmpconf.file);

+ 12 - 4
src/misc_file.c

@@ -194,13 +194,21 @@ error:
 //  fatal("Cannot create temporary file!", 0);
 }
 
-Tempfile::~Tempfile()
+void Tempfile::my_close()
 {
-  unlink(file);
-  if (f)
+  if (f) {
     fclose(f);
-  else
+    f = NULL;
+  } else if (fd >= 0) {
     close(fd);
+    fd = -1;
+  }
+}
+
+Tempfile::~Tempfile()
+{
+  unlink(file);
+  my_close();
   delete[] file;
 }
 

+ 1 - 0
src/misc_file.h

@@ -24,6 +24,7 @@ class Tempfile
   public:
     Tempfile();					//constructor
     Tempfile(const char *prefix);		//constructor with file prefix
+    void Tempfile::my_close();
     ~Tempfile();				//destructor
 
     bool error;					//exceptions are lame.