1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-12 13:17:58 +03:00

util: Fix resource leak

The virRotatingFileWriterAppend method leaks the file->entry
on the virRotatingFileWriterEntryNew failing path.
This commit is contained in:
Wang King 2017-04-12 16:44:04 +08:00 committed by John Ferlan
parent 9db0a63b7e
commit 123770cd4e

View File

@ -483,18 +483,19 @@ virRotatingFileWriterAppend(virRotatingFileWriterPtr file,
if ((file->entry->pos == file->maxlen && len) ||
forceRollover) {
virRotatingFileWriterEntryPtr tmp = file->entry;
virRotatingFileWriterEntryPtr tmp;
VIR_DEBUG("Hit max size %zu on %s (force=%d)\n",
file->maxlen, file->basepath, forceRollover);
if (virRotatingFileWriterRollover(file) < 0)
return -1;
if (!(file->entry = virRotatingFileWriterEntryNew(file->basepath,
file->mode)))
if (!(tmp = virRotatingFileWriterEntryNew(file->basepath,
file->mode)))
return -1;
virRotatingFileWriterEntryFree(tmp);
virRotatingFileWriterEntryFree(file->entry);
file->entry = tmp;
}
}