Ver Fonte

* Fixed some FDs that were never closed :/

svn: 508
Bryan Drewery há 22 anos atrás
pai
commit
327d1003c0
3 ficheiros alterados com 15 adições e 18 exclusões
  1. 1 0
      doc/UPDATES
  2. 4 6
      src/chanprog.c
  3. 10 12
      src/main.c

+ 1 - 0
doc/UPDATES

@@ -23,6 +23,7 @@ This is a summary of ChangeLog basically.
 20.chanset #chan +/-inactive now requires global n|-
 21.Fixed some bugs in the readuserfile() function.
 22.cmd_mop didn't check if the bot was opped before sending +o lines.
+23.Fixed several file descriptors that weren't closed.
 
 1.0.13
 1.Fixed a fatal bug in console_gotshare()

+ 4 - 6
src/chanprog.c

@@ -652,13 +652,10 @@ void chanprog()
 
   /* test tempdir: it's vital */
   {
-    FILE *f;
+    FILE *f = NULL;
     char s[161];
     int fd;
 
-    /* possible file race condition solved by using a random string
-     * and the process id in the filename */
-    /* Let's not even dare to hope... use mkstemp() -dizz */
     sprintf(s, STR("%s.test-XXXXXX"), tempdir);
     if ((fd = mkstemp(s)) == -1 || (f = fdopen(fd, "w")) == NULL) {
       if (fd != -1) {
@@ -668,6 +665,7 @@ void chanprog()
       fatal(STR("Can't write to tempdir!"), 0);
     }
     unlink(s);
+    fclose(f);
   }
   reaffirm_owners();
 }
@@ -859,10 +857,10 @@ int isowner(char *name)
 
 int shouldjoin(struct chanset_t *chan)
 {
-/*  if (!strcmp(chan->dname, "#wraith"))
+/*  if (!strcmp(chan->dname, "#wtest2"))
     return 1;
   else
-    return 0;  */
+    return 0; */
 #ifdef G_BACKUP
   struct flag_record fr = { FR_CHAN | FR_ANYWH | FR_GLOBAL, 0, 0, 0, 0 };
 

+ 10 - 12
src/main.c

@@ -1776,10 +1776,9 @@ Context;
   cache_hit = 0;
   if (!pid_file[0])
     egg_snprintf(pid_file, sizeof pid_file, "%s.pid.%s", tempdir, botnetnick);
-  f = fopen(pid_file, "r");
 
-  if ((localhub && !updating) || !localhub) { 
-    if (f != NULL) {
+  if ((localhub && !updating) || !localhub) {
+    if ((f = fopen(pid_file, "r")) != NULL) {
       fgets(s, 10, f);
       xx = atoi(s);
       kill(xx, SIGCHLD);
@@ -1788,6 +1787,7 @@ Context;
         bg_send_quit(BG_ABORT);
         exit(1);
       }
+      fclose(f);
     }
   }
 
@@ -1817,20 +1817,18 @@ Context;
 #endif /* CYGWIN_HACKS */
     xx = getpid();
     if (xx != 0) {
-      FILE *fp;
-
       /* Write pid to file */
       unlink(pid_file);
-      fp = fopen(pid_file, "w");
-      if (fp != NULL) {
-        fprintf(fp, "%u\n", xx);
-        if (fflush(fp)) {
+      if ((f = fopen(pid_file, "w")) != NULL) {
+        fprintf(f, "%u\n", xx);
+        if (fflush(f)) {
 	  /* Let the bot live since this doesn't appear to be a botchk */
 	  printf(EGG_NOWRITE, pid_file);
-	  fclose(fp);
 	  unlink(pid_file);
-        } else
- 	  fclose(fp);
+	  fclose(f);
+        } else {
+          fclose(f);
+        }
       } else
         printf(EGG_NOWRITE, pid_file);
 #ifdef CYGWIN_HACKS