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.
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);
}