From: Martin Mares Date: Thu, 19 Feb 2009 17:03:14 +0000 (+0100) Subject: Logging: Fixed a bug in log_close_all(). X-Git-Tag: holmes-import~57 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=1e3a1935f1b1778b40a7d5276c7b2f8c311756e7;p=libucw.git Logging: Fixed a bug in log_close_all(). Under some circumstances (involving loops in substream structure), log_close_all() crashed, because a stream could have become freed when removing its substreams. I have changed log_close_all() to unlink all substreams first and then proceed with deallocating memory. The same problem can never occur in simple log_close_stream(), because a stream that is a part of a loop never gets a use count of 0. --- diff --git a/ucw/log-stream.c b/ucw/log-stream.c index 1ca76a55..3e94d748 100644 --- a/ucw/log-stream.c +++ b/ucw/log-stream.c @@ -58,15 +58,17 @@ log_close_all(void) if (!log_initialized) return; - // Close all open streams + // Remove substreams of all streams for (int i=0; i < log_streams_after; i++) if (log_streams.ptr[i]->regnum >= 0) - log_close_stream(log_streams.ptr[i]); + log_rm_substream(log_streams.ptr[i], NULL); - // Free all cached structures + // Close all streams that remain and free all cached structures for (int i=0; i < log_streams_after; i++) { struct log_stream *ls = log_streams.ptr[i]; + if (ls->regnum >= 0) + log_close_stream(ls); ASSERT(ls->regnum < 0 || !ls->use_count); xfree(ls); }