util: Fix resource leak

The virRotatingFileWriterAppend method leaks the file->entry
on the virRotatingFileWriterEntryNew failing path.

(cherry picked from commit 123770cd4e)
This commit is contained in:
Wang King 2017-04-12 16:44:04 +08:00 committed by Cole Robinson
parent 0c20c9092c
commit 268c7e085a

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