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 <pkrempa(a)redhat.com>
---
src/libxl/libxl_logger.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
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);
}
--
2.31.1