From: Peter Krempa Date: Tue, 30 Nov 2021 10:34:43 +0000 (+0100) Subject: libxlLoggerNew: Avoid virHashFree by rearranging code X-Git-Tag: v8.0.0-rc1~428 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04bbaa2b1f828b83faea03041f246c14770726db;p=thirdparty%2Flibvirt.git libxlLoggerNew: Avoid virHashFree by rearranging code Allocate the hash table only after the log file is opened so that we don't need to deallocate it on failure. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko Reviewed-by: Martin Kletzander --- diff --git a/src/libxl/libxl_logger.c b/src/libxl/libxl_logger.c index f7b5c8ee16..4692578124 100644 --- a/src/libxl/libxl_logger.c +++ b/src/libxl/libxl_logger.c @@ -149,14 +149,13 @@ libxlLoggerNew(const char *logDir, virLogPriority minLevel) break; } logger.logDir = logDir; - logger.files = virHashNew(libxlLoggerFileFree); path = g_strdup_printf("%s/libxl-driver.log", logDir); - if ((logger.defaultLogFile = fopen(path, "a")) == NULL) { - virHashFree(logger.files); + if ((logger.defaultLogFile = fopen(path, "a")) == NULL) return NULL; - } + + logger.files = virHashNew(libxlLoggerFileFree); return XTL_NEW_LOGGER(libvirt, logger); }