fix(log): fix SLogDestroy() memory corruption

This commit is contained in:
VDm 2024-02-20 00:37:21 +04:00
parent b195319ff6
commit 96c121717b

View file

@ -414,12 +414,17 @@ int SLogIsInitialized() {
void SLogDestroy() { void SLogDestroy() {
for (size_t i = 0; i < STORM_LOG_MAX_CHANNELS; ++i) { for (size_t i = 0; i < STORM_LOG_MAX_CHANNELS; ++i) {
s_critsect[i]->Enter(); s_critsect[i]->Enter();
for (LOG* log = s_loghead[i]; log; log = log->next) { LOG* log = s_loghead[i];
while (log) {
if (log->file) { if (log->file) {
FlushLog(log); FlushLog(log);
fclose(log->file); fclose(log->file);
} }
LOG* next = log->next;
SMemFree(log);
log = next;
} }
s_loghead[i] = nullptr;
s_critsect[i]->Leave(); s_critsect[i]->Leave();
delete s_critsect[i]; delete s_critsect[i];
} }