updates.
authorPekka Riikonen <priikone@silcnet.org>
Thu, 7 Jun 2001 06:57:05 +0000 (06:57 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 7 Jun 2001 06:57:05 +0000 (06:57 +0000)
lib/silcutil/silclog.c
lib/silcutil/silcutil.c

index 13d186476cafa489e0d281358b22c0d8259dc2d5..91b254d508b90ec63960eec19d7ad3c8e2c96ae5 100644 (file)
@@ -107,6 +107,8 @@ void silc_log_output(const char *filename, uint32 maxsize,
       /* Purge? */
       if (filelen >= maxsize)
        unlink(filename);
+
+      fclose(fp);
     }
   }
 
@@ -126,7 +128,8 @@ void silc_log_output(const char *filename, uint32 maxsize,
 
   fprintf(fp, "[%s] [%s] %s\n", silc_get_time(), np->name, string);
   fflush(fp);
-  fclose(fp);
+  if (fp != stderr)
+    fclose(fp);
   silc_free(string);
 }
 
index 10b37f09df625321dcbc73f42d4236ca782ad934..3e969c73998fbd4638520bf13e0e3935d35aa672 100644 (file)
@@ -41,13 +41,18 @@ char *silc_file_read(const char *filename, uint32 *return_len)
   }
 
   filelen = lseek(fd, (off_t)0L, SEEK_END);
-  if (filelen < 0)
+  if (filelen < 0) {
+    close(fd);
     return NULL;
-  if (lseek(fd, (off_t)0L, SEEK_SET) < 0)
+  }
+  if (lseek(fd, (off_t)0L, SEEK_SET) < 0) {
+    close(fd);
     return NULL;
+  }
 
   if (filelen < 0) {
     SILC_LOG_ERROR(("Cannot open file %s: %s", filename, strerror(errno)));
+    close(fd);
     return NULL;
   }
   
@@ -84,6 +89,7 @@ int silc_file_write(const char *filename, const char *buffer, uint32 len)
   
   if ((write(fd, buffer, len)) == -1) {
     SILC_LOG_ERROR(("Cannot write to file %s: %s", filename, strerror(errno)));
+    close(fd);
     return -1;
   }
 
@@ -108,6 +114,7 @@ int silc_file_write_mode(const char *filename, const char *buffer,
   
   if ((write(fd, buffer, len)) == -1) {
     SILC_LOG_ERROR(("Cannot write to file %s: %s", filename, strerror(errno)));
+    close(fd);
     return -1;
   }