]> mj.ucw.cz Git - libucw.git/commitdiff
Logging: Fix log_close_all().
authorMartin Mares <mj@ucw.cz>
Sat, 14 Feb 2009 22:25:33 +0000 (23:25 +0100)
committerMartin Mares <mj@ucw.cz>
Sat, 14 Feb 2009 22:25:33 +0000 (23:25 +0100)
Closing of streams and freeing of memory has to be separate since we introduced
use counts.

ucw/log-stream.c
ucw/log.c

index 468d6f7ddae4afb7273205921f9a384ef05e2334..097faef905440873a47a6f3aa50409b3de76043a 100644 (file)
@@ -60,13 +60,14 @@ log_close_all(void)
   if (!log_initialized)
     return;
 
-  // FIXME!
+  // Close all open streams
   for (int i=0; i < log_streams_after; i++)
-    {
-      if (log_streams.ptr[i]->regnum >= 0)
-       log_close_stream(log_streams.ptr[i]);
-      xfree(log_streams.ptr[i]);
-    }
+    if (log_streams.ptr[i]->regnum >= 0)
+      log_close_stream(log_streams.ptr[i]);
+
+  // Free all cached structures
+  for (int i=0; i < log_streams_after; i++)
+    xfree(log_streams.ptr[i]);
 
   /* Back to the default state */
   lsbuf_done(&log_streams);
index 7761401b8ac4ca49fdc7a7a91c102927ad670611..c6a095be4b218cfb8af5728000c6903913fdfb96 100644 (file)
--- a/ucw/log.c
+++ b/ucw/log.c
@@ -336,6 +336,7 @@ int main(void)
   msg(L_INFO | ls->regnum, "Brum <%300s>", ":-)");
   log_set_format(log_default_stream(), ~0U, LSFMT_USEC);
   msg(L_INFO, "Brum <%300s>", ":-)");
+  log_close_all();
   return 0;
 }