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 <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Peter Krempa 2021-11-30 11:34:43 +01:00
parent 35ebb28f3f
commit 04bbaa2b1f

View File

@ -149,14 +149,13 @@ libxlLoggerNew(const char *logDir, virLogPriority minLevel)
break; break;
} }
logger.logDir = logDir; logger.logDir = logDir;
logger.files = virHashNew(libxlLoggerFileFree);
path = g_strdup_printf("%s/libxl-driver.log", logDir); path = g_strdup_printf("%s/libxl-driver.log", logDir);
if ((logger.defaultLogFile = fopen(path, "a")) == NULL) { if ((logger.defaultLogFile = fopen(path, "a")) == NULL)
virHashFree(logger.files);
return NULL; return NULL;
}
logger.files = virHashNew(libxlLoggerFileFree);
return XTL_NEW_LOGGER(libvirt, logger); return XTL_NEW_LOGGER(libvirt, logger);
} }