On 2/16/21 6:40 PM, Jim Fehlig wrote:
All of these strings are allocated once, freed once, and are never
returned out of the function where they are declared.
Signed-off-by: Jim Fehlig <jfehlig(a)suse.com>
---
src/libxl/libxl_capabilities.c | 3 +--
src/libxl/libxl_domain.c | 17 +++++------------
src/libxl/libxl_driver.c | 32 +++++++++++---------------------
src/libxl/libxl_logger.c | 21 ++++++---------------
src/libxl/libxl_migration.c | 15 +++++----------
src/libxl/xen_common.c | 17 ++++++-----------
src/libxl/xen_xl.c | 6 ++----
7 files changed, 36 insertions(+), 75 deletions(-)
[snip]
@@ -135,7 +133,7 @@ libxlLoggerNew(const char *logDir, virLogPriority
minLevel)
{
xentoollog_logger_libvirt logger;
libxlLoggerPtr logger_out = NULL;
- char *path = NULL;
+ g_autofree char *path = NULL;
switch (minLevel) {
case VIR_LOG_DEBUG:
@@ -164,7 +162,6 @@ libxlLoggerNew(const char *logDir, virLogPriority minLevel)
logger_out = XTL_NEW_LOGGER(libvirt, logger);
cleanup:
- VIR_FREE(path);
return logger_out;
error:
With nothing more to cleanup, this function could be reduced a bit more. I've
squashed the following into my local branch
diff --git a/src/libxl/libxl_logger.c b/src/libxl/libxl_logger.c
index 39e59d9231..1da3357c6d 100644
--- a/src/libxl/libxl_logger.c
+++ b/src/libxl/libxl_logger.c
@@ -132,7 +132,6 @@ libxlLoggerPtr
libxlLoggerNew(const char *logDir, virLogPriority minLevel)
{
xentoollog_logger_libvirt logger;
- libxlLoggerPtr logger_out = NULL;
g_autofree char *path = NULL;
switch (minLevel) {
@@ -156,17 +155,12 @@ libxlLoggerNew(const char *logDir, virLogPriority minLevel)
path = g_strdup_printf("%s/libxl-driver.log", logDir);
- if ((logger.defaultLogFile = fopen(path, "a")) == NULL)
- goto error;
+ if ((logger.defaultLogFile = fopen(path, "a")) == NULL) {
+ virHashFree(logger.files);
+ return NULL;
+ }
- logger_out = XTL_NEW_LOGGER(libvirt, logger);
-
- cleanup:
- return logger_out;
-
- error:
- virHashFree(logger.files);
- goto cleanup;
+ return XTL_NEW_LOGGER(libvirt, logger);
}
void