Re: [PATCH 6/6] lib: Define and use autofree for virConfPtr

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 9/9/19 1:00 PM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---

Reviewed-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>


  src/bhyve/bhyve_conf.c            | 10 +---
  src/libvirt-admin.c               |  3 +-
  src/libvirt.c                     |  4 +-
  src/libxl/libxl_conf.c            | 22 +++-----
  src/libxl/libxl_driver.c          |  8 +--
  src/libxl/xen_xl.c                | 33 +++++------
  src/libxl/xen_xm.c                | 19 +++----
  src/locking/lock_daemon_config.c  |  7 +--
  src/locking/lock_driver_lockd.c   | 18 +++---
  src/locking/lock_driver_sanlock.c |  3 +-
  src/logging/log_daemon_config.c   |  7 +--
  src/lxc/lxc_conf.c                | 16 ++----
  src/lxc/lxc_native.c              | 15 ++---
  src/qemu/qemu_conf.c              | 47 +++++++---------
  src/remote/remote_daemon_config.c | 14 ++---
  src/security/security_selinux.c   |  4 +-
  src/util/virconf.h                |  2 +
  src/vmx/vmx.c                     |  3 +-
  tests/virconftest.c               | 93 +++++++++++++------------------
  tests/xlconfigtest.c              |  8 +--
  tests/xmconfigtest.c              |  8 +--
  tools/virt-login-shell-helper.c   |  3 +-
  22 files changed, 133 insertions(+), 214 deletions(-)

diff --git a/src/bhyve/bhyve_conf.c b/src/bhyve/bhyve_conf.c
index ee9427ea18..946be4a811 100644
--- a/src/bhyve/bhyve_conf.c
+++ b/src/bhyve/bhyve_conf.c
@@ -70,8 +70,7 @@ int
  virBhyveLoadDriverConfig(virBhyveDriverConfigPtr cfg,
                           const char *filename)
  {
-    virConfPtr conf;
-    int ret = -1;
+    VIR_AUTOPTR(virConf) conf = NULL;
if (access(filename, R_OK) == -1) {
          VIR_INFO("Could not read bhyve config file %s", filename);
@@ -83,12 +82,9 @@ virBhyveLoadDriverConfig(virBhyveDriverConfigPtr cfg,
if (virConfGetValueString(conf, "firmware_dir",
                                &cfg->firmwareDir) < 0)
-        goto cleanup;
+        return -1;
- ret = 0;
- cleanup:
-    virConfFree(conf);
-    return ret;
+    return 0;
  }
virBhyveDriverConfigPtr
diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c
index ba88f09824..9d5c5b1b7b 100644
--- a/src/libvirt-admin.c
+++ b/src/libvirt-admin.c
@@ -223,7 +223,7 @@ virAdmConnectOpen(const char *name, unsigned int flags)
      char *sock_path = NULL;
      char *alias = NULL;
      virAdmConnectPtr conn = NULL;
-    virConfPtr conf = NULL;
+    VIR_AUTOPTR(virConf) conf = NULL;
      char *uristr = NULL;
if (virAdmInitialize() < 0)
@@ -272,7 +272,6 @@ virAdmConnectOpen(const char *name, unsigned int flags)
   cleanup:
      VIR_FREE(sock_path);
      VIR_FREE(uristr);
-    virConfFree(conf);
      return conn;
error:
diff --git a/src/libvirt.c b/src/libvirt.c
index 9650aaa453..19bc05638f 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -859,7 +859,7 @@ virConnectOpenInternal(const char *name,
      size_t i;
      int res;
      virConnectPtr ret;
-    virConfPtr conf = NULL;
+    VIR_AUTOPTR(virConf) conf = NULL;
      char *uristr = NULL;
ret = virGetConnect();
@@ -1069,14 +1069,12 @@ virConnectOpenInternal(const char *name,
          goto failed;
      }
- virConfFree(conf);
      VIR_FREE(uristr);
return ret; failed:
      VIR_FREE(uristr);
-    virConfFree(conf);
      virObjectUnref(ret);
return NULL;
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 766a726ebc..c76704a11d 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1864,8 +1864,7 @@ libxlDriverConfigGet(libxlDriverPrivatePtr driver)
  int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
                                const char *filename)
  {
-    virConfPtr conf = NULL;
-    int ret = -1;
+    VIR_AUTOPTR(virConf) conf = NULL;
/* defaults for keepalive messages */
      cfg->keepAliveInterval = 5;
@@ -1880,30 +1879,25 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
      }
if (!(conf = virConfReadFile(filename, 0)))
-        goto cleanup;
+        return -1;
/* setup autoballoon */
      if (libxlGetAutoballoonConf(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virConfGetValueString(conf, "lock_manager", &cfg->lockManagerName) < 0)
-        goto cleanup;
+        return -1;
if (virConfGetValueInt(conf, "keepalive_interval", &cfg->keepAliveInterval) < 0)
-        goto cleanup;
+        return -1;
if (virConfGetValueUInt(conf, "keepalive_count", &cfg->keepAliveCount) < 0)
-        goto cleanup;
+        return -1;
if (virConfGetValueBool(conf, "nested_hvm", &cfg->nested_hvm) < 0)
-        goto cleanup;
-
-    ret = 0;
-
- cleanup:
-    virConfFree(conf);
-    return ret;
+        return -1;
+ return 0;
  }
/*
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index fccc1f42e8..45de6b24c6 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2675,7 +2675,7 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn,
      libxlDriverPrivatePtr driver = conn->privateData;
      libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
      virDomainDefPtr def = NULL;
-    virConfPtr conf = NULL;
+    VIR_AUTOPTR(virConf) conf = NULL;
      char *xml = NULL;
virCheckFlags(0, NULL);
@@ -2712,8 +2712,6 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn,
cleanup:
      virDomainDefFree(def);
-    if (conf)
-        virConfFree(conf);
      virObjectUnref(cfg);
      return xml;
  }
@@ -2727,7 +2725,7 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
      libxlDriverPrivatePtr driver = conn->privateData;
      libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
      virDomainDefPtr def = NULL;
-    virConfPtr conf = NULL;
+    VIR_AUTOPTR(virConf) conf = NULL;
      int len = MAX_CONFIG_SIZE;
      char *ret = NULL;
@@ -2764,8 +2762,6 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat, cleanup:
      virDomainDefFree(def);
-    if (conf)
-        virConfFree(conf);
      virObjectUnref(cfg);
      return ret;
  }
diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c
index ca094d30c2..3a41a4ad00 100644
--- a/src/libxl/xen_xl.c
+++ b/src/libxl/xen_xl.c
@@ -2198,52 +2198,47 @@ xenFormatXLDomainChannels(virConfPtr conf, virDomainDefPtr def)
  virConfPtr
  xenFormatXL(virDomainDefPtr def, virConnectPtr conn)
  {
-    virConfPtr conf = NULL;
+    VIR_AUTOPTR(virConf) conf = NULL;
if (!(conf = virConfNew()))
-        goto cleanup;
+        return NULL;
if (xenFormatConfigCommon(conf, def, conn, XEN_CONFIG_FORMAT_XL) < 0)
-        goto cleanup;
+        return NULL;
if (xenFormatXLOS(conf, def) < 0)
-        goto cleanup;
+        return NULL;
if (xenFormatXLCPUID(conf, def) < 0)
-        goto cleanup;
+        return NULL;
#ifdef LIBXL_HAVE_VNUMA
      if (xenFormatXLDomainVnuma(conf, def) < 0)
-        goto cleanup;
+        return NULL;
  #endif
#ifdef LIBXL_HAVE_BUILDINFO_GRANT_LIMITS
      if (xenFormatXLGntLimits(conf, def) < 0)
-        goto cleanup;
+        return NULL;
  #endif
if (xenFormatXLDomainDisks(conf, def) < 0)
-        goto cleanup;
+        return NULL;
if (xenFormatXLSpice(conf, def) < 0)
-        goto cleanup;
+        return NULL;
if (xenFormatXLInputDevs(conf, def) < 0)
-        goto cleanup;
+        return NULL;
if (xenFormatXLUSB(conf, def) < 0)
-        goto cleanup;
+        return NULL;
if (xenFormatXLUSBController(conf, def) < 0)
-        goto cleanup;
+        return NULL;
if (xenFormatXLDomainChannels(conf, def) < 0)
-        goto cleanup;
+        return NULL;
- return conf;
-
- cleanup:
-    if (conf)
-        virConfFree(conf);
-    return NULL;
+    VIR_RETURN_PTR(conf);
  }
diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c
index b8dee0917e..0296e78ddc 100644
--- a/src/libxl/xen_xm.c
+++ b/src/libxl/xen_xm.c
@@ -599,27 +599,22 @@ virConfPtr
  xenFormatXM(virConnectPtr conn,
              virDomainDefPtr def)
  {
-    virConfPtr conf = NULL;
+    VIR_AUTOPTR(virConf) conf = NULL;
if (!(conf = virConfNew()))
-        goto cleanup;
+        return NULL;
if (xenFormatConfigCommon(conf, def, conn, XEN_CONFIG_FORMAT_XM) < 0)
-        goto cleanup;
+        return NULL;
if (xenFormatXMOS(conf, def) < 0)
-        goto cleanup;
+        return NULL;
if (xenFormatXMDisks(conf, def) < 0)
-        goto cleanup;
+        return NULL;
if (xenFormatXMInputDevs(conf, def) < 0)
-        goto cleanup;
+        return NULL;
- return conf;
-
- cleanup:
-    if (conf)
-        virConfFree(conf);
-    return NULL;
+    VIR_RETURN_PTR(conf);
  }
diff --git a/src/locking/lock_daemon_config.c b/src/locking/lock_daemon_config.c
index 03feeb02a5..8df7cf89cd 100644
--- a/src/locking/lock_daemon_config.c
+++ b/src/locking/lock_daemon_config.c
@@ -114,8 +114,7 @@ virLockDaemonConfigLoadFile(virLockDaemonConfigPtr data,
                              const char *filename,
                              bool allow_missing)
  {
-    virConfPtr conf;
-    int ret;
+    VIR_AUTOPTR(virConf) conf = NULL;
if (allow_missing &&
          access(filename, R_OK) == -1 &&
@@ -126,7 +125,5 @@ virLockDaemonConfigLoadFile(virLockDaemonConfigPtr data,
      if (!conf)
          return -1;
- ret = virLockDaemonConfigLoadOptions(data, conf);
-    virConfFree(conf);
-    return ret;
+    return virLockDaemonConfigLoadOptions(data, conf);
  }
diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c
index 164f83eb4b..67f512a64e 100644
--- a/src/locking/lock_driver_lockd.c
+++ b/src/locking/lock_driver_lockd.c
@@ -81,8 +81,7 @@ static virLockManagerLockDaemonDriverPtr driver;
static int virLockManagerLockDaemonLoadConfig(const char *configFile)
  {
-    virConfPtr conf;
-    int ret = -1;
+    VIR_AUTOPTR(virConf) conf = NULL;
if (access(configFile, R_OK) == -1) {
          if (errno != ENOENT) {
@@ -98,25 +97,22 @@ static int virLockManagerLockDaemonLoadConfig(const char *configFile)
          return -1;
if (virConfGetValueBool(conf, "auto_disk_leases", &driver->autoDiskLease) < 0)
-        goto cleanup;
+        return -1;
if (virConfGetValueString(conf, "file_lockspace_dir", &driver->fileLockSpaceDir) < 0)
-        goto cleanup;
+        return -1;
if (virConfGetValueString(conf, "lvm_lockspace_dir", &driver->lvmLockSpaceDir) < 0)
-        goto cleanup;
+        return -1;
if (virConfGetValueString(conf, "scsi_lockspace_dir", &driver->scsiLockSpaceDir) < 0)
-        goto cleanup;
+        return -1;
driver->requireLeaseForDisks = !driver->autoDiskLease;
      if (virConfGetValueBool(conf, "require_lease_for_disks", &driver->requireLeaseForDisks) < 0)
-        goto cleanup;
+        return -1;
- ret = 0;
- cleanup:
-    virConfFree(conf);
-    return ret;
+    return 0;
  }
diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c
index ff0c9be8f7..85a23c7642 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -119,7 +119,7 @@ static int
  virLockManagerSanlockLoadConfig(virLockManagerSanlockDriverPtr driver,
                                  const char *configFile)
  {
-    virConfPtr conf;
+    VIR_AUTOPTR(virConf) conf = NULL;
      int ret = -1;
      char *user = NULL;
      char *group = NULL;
@@ -167,7 +167,6 @@ virLockManagerSanlockLoadConfig(virLockManagerSanlockDriverPtr driver,
ret = 0;
   cleanup:
-    virConfFree(conf);
      VIR_FREE(user);
      VIR_FREE(group);
      return ret;
diff --git a/src/logging/log_daemon_config.c b/src/logging/log_daemon_config.c
index ec6d0686f4..c7dfa19b5d 100644
--- a/src/logging/log_daemon_config.c
+++ b/src/logging/log_daemon_config.c
@@ -120,8 +120,7 @@ virLogDaemonConfigLoadFile(virLogDaemonConfigPtr data,
                             const char *filename,
                             bool allow_missing)
  {
-    virConfPtr conf;
-    int ret;
+    VIR_AUTOPTR(virConf) conf = NULL;
if (allow_missing &&
          access(filename, R_OK) == -1 &&
@@ -132,7 +131,5 @@ virLogDaemonConfigLoadFile(virLogDaemonConfigPtr data,
      if (!conf)
          return -1;
- ret = virLogDaemonConfigLoadOptions(data, conf);
-    virConfFree(conf);
-    return ret;
+    return virLogDaemonConfigLoadOptions(data, conf);
  }
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index 2e4cc4f51a..9d1653f437 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -252,8 +252,7 @@ int
  virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg,
                         const char *filename)
  {
-    virConfPtr conf;
-    int ret = -1;
+    VIR_AUTOPTR(virConf) conf = NULL;
/* Avoid error from non-existent or unreadable file. */
      if (access(filename, R_OK) == -1)
@@ -264,21 +263,18 @@ virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg,
          return -1;
if (virConfGetValueBool(conf, "log_with_libvirtd", &cfg->log_libvirtd) < 0)
-        goto cleanup;
+        return -1;
if (virConfGetValueString(conf, "security_driver", &cfg->securityDriverName) < 0)
-        goto cleanup;
+        return -1;
if (virConfGetValueBool(conf, "security_default_confined", &cfg->securityDefaultConfined) < 0)
-        goto cleanup;
+        return -1;
if (virConfGetValueBool(conf, "security_require_confined", &cfg->securityRequireConfined) < 0)
-        goto cleanup;
+        return -1;
- ret = 0;
- cleanup:
-    virConfFree(conf);
-    return ret;
+    return 0;
  }
virLXCDriverConfigPtr virLXCDriverGetConfig(virLXCDriverPtr driver)
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index bb8c359147..f9d43a1b3e 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -1079,7 +1079,7 @@ lxcParseConfigString(const char *config,
                       virDomainXMLOptionPtr xmlopt)
  {
      virDomainDefPtr vmdef = NULL;
-    virConfPtr properties = NULL;
+    VIR_AUTOPTR(virConf) properties = NULL;
      VIR_AUTOFREE(char *) value = NULL;
if (!(properties = virConfReadString(config, VIR_CONF_FLAG_LXC_FORMAT)))
@@ -1192,14 +1192,9 @@ lxcParseConfigString(const char *config,
                                xmlopt, NULL) < 0)
          goto error;
- goto cleanup;
-
- error:
-    virDomainDefFree(vmdef);
-    vmdef = NULL;
-
- cleanup:
-    virConfFree(properties);
-
      return vmdef;
+
+ error:
+    virDomainDefFree(vmdef);
+    return NULL;
  }
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index f805991872..dd571cb3aa 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1000,8 +1000,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
                                  const char *filename,
                                  bool privileged)
  {
-    virConfPtr conf = NULL;
-    int ret = -1;
+    VIR_AUTOPTR(virConf) conf = NULL;
/* Just check the file is readable before opening it, otherwise
       * libvirt emits an error.
@@ -1012,67 +1011,63 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
      }
if (!(conf = virConfReadFile(filename, 0)))
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadDefaultTLSEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadVNCEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadNographicsEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadSPICEEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadSpecificTLSEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadRemoteDisplayEntry(cfg, conf, filename) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadSaveEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadProcessEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadDeviceEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadRPCEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadNetworkEntry(cfg, conf, filename) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadLogEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadNVRAMEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadGlusterDebugEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadSecurityEntry(cfg, conf, privileged) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadMemoryEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadSWTPMEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
if (virQEMUDriverConfigLoadCapsFiltersEntry(cfg, conf) < 0)
-        goto cleanup;
+        return -1;
- ret = 0;
-
- cleanup:
-    virConfFree(conf);
-    return ret;
+    return 0;
  }
diff --git a/src/remote/remote_daemon_config.c b/src/remote/remote_daemon_config.c
index b224e75a18..0eecb20c34 100644
--- a/src/remote/remote_daemon_config.c
+++ b/src/remote/remote_daemon_config.c
@@ -401,8 +401,7 @@ daemonConfigLoadFile(struct daemonConfig *data,
                       const char *filename,
                       bool allow_missing)
  {
-    virConfPtr conf;
-    int ret;
+    VIR_AUTOPTR(virConf) conf = NULL;
if (allow_missing &&
          access(filename, R_OK) == -1 &&
@@ -413,23 +412,18 @@ daemonConfigLoadFile(struct daemonConfig *data,
      if (!conf)
          return -1;
- ret = daemonConfigLoadOptions(data, filename, conf);
-    virConfFree(conf);
-    return ret;
+    return daemonConfigLoadOptions(data, filename, conf);
  }
int daemonConfigLoadData(struct daemonConfig *data,
                           const char *filename,
                           const char *filedata)
  {
-    virConfPtr conf;
-    int ret;
+    VIR_AUTOPTR(virConf) conf = NULL;
conf = virConfReadString(filedata, 0);
      if (!conf)
          return -1;
- ret = daemonConfigLoadOptions(data, filename, conf);
-    virConfFree(conf);
-    return ret;
+    return daemonConfigLoadOptions(data, filename, conf);
  }
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index af7f62dfd9..e879fa39ab 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -635,7 +635,7 @@ virSecuritySELinuxGenNewContext(const char *basecontext,
  static int
  virSecuritySELinuxLXCInitialize(virSecurityManagerPtr mgr)
  {
-    virConfPtr selinux_conf;
+    VIR_AUTOPTR(virConf) selinux_conf = NULL;
      virSecuritySELinuxDataPtr data = virSecurityManagerGetPrivateData(mgr);
data->skipAllLabel = true;
@@ -685,7 +685,6 @@ virSecuritySELinuxLXCInitialize(virSecurityManagerPtr mgr)
      if (!(data->mcs = virHashCreate(10, NULL)))
          goto error;
- virConfFree(selinux_conf);
      return 0;
error:
@@ -693,7 +692,6 @@ virSecuritySELinuxLXCInitialize(virSecurityManagerPtr mgr)
      selabel_close(data->label_handle);
      data->label_handle = NULL;
  # endif
-    virConfFree(selinux_conf);
      VIR_FREE(data->domain_context);
      VIR_FREE(data->file_context);
      VIR_FREE(data->content_context);
diff --git a/src/util/virconf.h b/src/util/virconf.h
index ed9d404a1e..4c0c633aad 100644
--- a/src/util/virconf.h
+++ b/src/util/virconf.h
@@ -22,6 +22,7 @@
#include "virutil.h"
  #include "virenum.h"
+#include "virautoclean.h"
/**
   * virConfType:
@@ -80,6 +81,7 @@ virConfPtr virConfReadFile(const char *filename, unsigned int flags);
  virConfPtr virConfReadString(const char *memory,
                               unsigned int flags);
  int virConfFree(virConfPtr conf);
+VIR_DEFINE_AUTOPTR_FUNC(virConf, virConfFree);
  void virConfFreeValue(virConfValuePtr val);
  virConfValuePtr virConfGetValue(virConfPtr conf,
                                  const char *setting);
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 2cc0995783..d8f15b5b47 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1275,7 +1275,7 @@ virVMXParseConfig(virVMXContext *ctx,
                    const char *vmx)
  {
      bool success = false;
-    virConfPtr conf = NULL;
+    VIR_AUTOPTR(virConf) conf = NULL;
      char *encoding = NULL;
      char *utf8;
      virDomainDefPtr def = NULL;
@@ -1850,7 +1850,6 @@ virVMXParseConfig(virVMXContext *ctx,
          def = NULL;
      }
- virConfFree(conf);
      VIR_FREE(encoding);
      VIR_FREE(sched_cpu_affinity);
      VIR_FREE(sched_cpu_shares);
diff --git a/tests/virconftest.c b/tests/virconftest.c
index cc2b26687c..f61e4ea9d5 100644
--- a/tests/virconftest.c
+++ b/tests/virconftest.c
@@ -33,7 +33,7 @@ static int testConfRoundTrip(const void *opaque)
  {
      const char *name = opaque;
      int ret = -1;
-    virConfPtr conf = NULL;
+    VIR_AUTOPTR(virConf) conf = NULL;
      int len = 10000;
      char *buffer = NULL;
      char *srcfile = NULL;
@@ -68,7 +68,6 @@ static int testConfRoundTrip(const void *opaque)
      VIR_FREE(srcfile);
      VIR_FREE(dstfile);
      VIR_FREE(buffer);
-    virConfFree(conf);
      return ret;
  }
@@ -80,7 +79,7 @@ static int testConfMemoryNoNewline(const void *opaque ATTRIBUTE_UNUSED)
          "string = 'foo'\n" \
          "uint = 12345";
- virConfPtr conf = virConfReadString(srcdata, 0);
+    VIR_AUTOPTR(virConf) conf = virConfReadString(srcdata, 0);
      int ret = -1;
      virConfValuePtr val;
      unsigned long long llvalue;
@@ -134,7 +133,6 @@ static int testConfMemoryNoNewline(const void *opaque ATTRIBUTE_UNUSED)
      ret = 0;
   cleanup:
      VIR_FREE(str);
-    virConfFree(conf);
      return ret;
  }
@@ -150,8 +148,7 @@ static int testConfParseInt(const void *opaque ATTRIBUTE_UNUSED)
          "ssize_t = -87539319\n" \
          "string = \"foo\"\n";
- int ret = -1;
-    virConfPtr conf = virConfReadString(srcdata, 0);
+    VIR_AUTOPTR(virConf) conf = virConfReadString(srcdata, 0);
      int iv;
      unsigned int ui;
      size_t s;
@@ -165,40 +162,40 @@ static int testConfParseInt(const void *opaque ATTRIBUTE_UNUSED)
      if (virConfGetValueType(conf, "int") !=
          VIR_CONF_LLONG) {
          fprintf(stderr, "expected a long for 'int'\n");
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueInt(conf, "int", &iv) < 0)
-        goto cleanup;
+        return -1;
if (iv != -1729) {
          fprintf(stderr, "Expected -1729 got %d\n", iv);
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueInt(conf, "string", &iv) != -1) {
          fprintf(stderr, "Expected error for 'string' param\n");
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueType(conf, "uint") !=
          VIR_CONF_ULLONG) {
          fprintf(stderr, "expected a unsigned long for 'uint'\n");
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueUInt(conf, "uint", &ui) < 0)
-        goto cleanup;
+        return -1;
if (ui != 1729) {
          fprintf(stderr, "Expected 1729 got %u\n", ui);
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueUInt(conf, "string", &ui) != -1) {
          fprintf(stderr, "Expected error for 'string' param\n");
-        goto cleanup;
+        return -1;
      }
@@ -206,20 +203,20 @@ static int testConfParseInt(const void *opaque ATTRIBUTE_UNUSED)
      if (virConfGetValueType(conf, "llong") !=
          VIR_CONF_LLONG) {
          fprintf(stderr, "expected a long for 'llong'\n");
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueLLong(conf, "llong", &l) < 0)
-        goto cleanup;
+        return -1;
if (l != -6963472309248) {
          fprintf(stderr, "Expected -6963472309248 got %lld\n", l);
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueLLong(conf, "string", &l) != -1) {
          fprintf(stderr, "Expected error for 'string' param\n");
-        goto cleanup;
+        return -1;
      }
@@ -227,20 +224,20 @@ static int testConfParseInt(const void *opaque ATTRIBUTE_UNUSED)
      if (virConfGetValueType(conf, "ullong") !=
          VIR_CONF_ULLONG) {
          fprintf(stderr, "expected a unsigned long for 'ullong'\n");
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueULLong(conf, "ullong", &ul) < 0)
-        goto cleanup;
+        return -1;
if (ul != 6963472309248) {
          fprintf(stderr, "Expected 6963472309248 got %llu\n", ul);
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueULLong(conf, "string", &ul) != -1) {
          fprintf(stderr, "Expected error for 'string' param\n");
-        goto cleanup;
+        return -1;
      }
@@ -248,20 +245,20 @@ static int testConfParseInt(const void *opaque ATTRIBUTE_UNUSED)
      if (virConfGetValueType(conf, "size_t") !=
          VIR_CONF_ULLONG) {
          fprintf(stderr, "expected a unsigned long for 'size_T'\n");
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueSizeT(conf, "size_t", &s) < 0)
-        goto cleanup;
+        return -1;
if (s != 87539319) {
          fprintf(stderr, "Expected 87539319 got %zu\n", s);
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueSizeT(conf, "string", &s) != -1) {
          fprintf(stderr, "Expected error for 'string' param\n");
-        goto cleanup;
+        return -1;
      }
@@ -269,26 +266,23 @@ static int testConfParseInt(const void *opaque ATTRIBUTE_UNUSED)
      if (virConfGetValueType(conf, "ssize_t") !=
          VIR_CONF_LLONG) {
          fprintf(stderr, "expected a unsigned long for 'ssize_t'\n");
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueSSizeT(conf, "ssize_t", &ss) < 0)
-        goto cleanup;
+        return -1;
if (ss != -87539319) {
          fprintf(stderr, "Expected -87539319 got %zd\n", ss);
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueSSizeT(conf, "string", &ss) != -1) {
          fprintf(stderr, "Expected error for 'string' param\n");
-        goto cleanup;
+        return -1;
      }
- ret = 0;
- cleanup:
-    virConfFree(conf);
-    return ret;
+    return 0;
  }
static int testConfParseBool(const void *opaque ATTRIBUTE_UNUSED)
@@ -299,8 +293,7 @@ static int testConfParseBool(const void *opaque ATTRIBUTE_UNUSED)
          "int = 6963472309248\n" \
          "string = \"foo\"\n";
- int ret = -1;
-    virConfPtr conf = virConfReadString(srcdata, 0);
+    VIR_AUTOPTR(virConf) conf = virConfReadString(srcdata, 0);
      bool f = true;
      bool t = false;
@@ -310,15 +303,15 @@ static int testConfParseBool(const void *opaque ATTRIBUTE_UNUSED)
      if (virConfGetValueType(conf, "false") !=
          VIR_CONF_ULLONG) {
          fprintf(stderr, "expected a long for 'false'\n");
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueBool(conf, "false", &f) < 0)
-        goto cleanup;
+        return -1;
if (f != false) {
          fprintf(stderr, "Expected 0 got %d\n", f);
-        goto cleanup;
+        return -1;
      }
@@ -326,34 +319,30 @@ static int testConfParseBool(const void *opaque ATTRIBUTE_UNUSED)
      if (virConfGetValueType(conf, "true") !=
          VIR_CONF_ULLONG) {
          fprintf(stderr, "expected a long for 'true'\n");
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueBool(conf, "true", &t) < 0)
-        goto cleanup;
+        return -1;
if (t != true) {
          fprintf(stderr, "Expected 1 got %d\n", t);
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueBool(conf, "int", &t) != -1) {
          fprintf(stderr, "Expected error for 'string' param\n");
-        goto cleanup;
+        return -1;
      }
if (virConfGetValueBool(conf, "string", &t) != -1) {
          fprintf(stderr, "Expected error for 'string' param\n");
-        goto cleanup;
+        return -1;
      }
-
-    ret = 0;
- cleanup:
-    virConfFree(conf);
-    return ret;
+    return 0;
  }
@@ -364,7 +353,7 @@ static int testConfParseString(const void *opaque ATTRIBUTE_UNUSED)
          "string = \"foo\"\n";
int ret = -1;
-    virConfPtr conf = virConfReadString(srcdata, 0);
+    VIR_AUTOPTR(virConf) conf = virConfReadString(srcdata, 0);
      char *str = NULL;
if (!conf)
@@ -392,7 +381,6 @@ static int testConfParseString(const void *opaque ATTRIBUTE_UNUSED)
      ret = 0;
   cleanup:
      VIR_FREE(str);
-    virConfFree(conf);
      return ret;
  }
@@ -404,7 +392,7 @@ static int testConfParseStringList(const void *opaque ATTRIBUTE_UNUSED)
          "string = \"foo\"\n";
int ret = -1;
-    virConfPtr conf = virConfReadString(srcdata, 0);
+    VIR_AUTOPTR(virConf) conf = virConfReadString(srcdata, 0);
      char **str = NULL;
if (!conf)
@@ -457,7 +445,6 @@ static int testConfParseStringList(const void *opaque ATTRIBUTE_UNUSED)
      ret = 0;
   cleanup:
      virStringListFree(str);
-    virConfFree(conf);
      return ret;
  }
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
index ae0db71293..80ac9b2c9a 100644
--- a/tests/xlconfigtest.c
+++ b/tests/xlconfigtest.c
@@ -68,7 +68,7 @@ static int
  testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
  {
      char *gotxlcfgData = NULL;
-    virConfPtr conf = NULL;
+    VIR_AUTOPTR(virConf) conf = NULL;
      virConnectPtr conn = NULL;
      int wrote = 4096;
      int ret = -1;
@@ -113,8 +113,6 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
   fail:
      VIR_FREE(replacedXML);
      VIR_FREE(gotxlcfgData);
-    if (conf)
-        virConfFree(conf);
      virDomainDefFree(def);
      virObjectUnref(conn);
@@ -130,7 +128,7 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
  {
      char *xlcfgData = NULL;
      char *gotxml = NULL;
-    virConfPtr conf = NULL;
+    VIR_AUTOPTR(virConf) conf = NULL;
      int ret = -1;
      virConnectPtr conn;
      virDomainDefPtr def = NULL;
@@ -165,8 +163,6 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
      ret = 0;
fail:
-    if (conf)
-        virConfFree(conf);
      VIR_FREE(replacedXML);
      VIR_FREE(xlcfgData);
      VIR_FREE(gotxml);
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index 3137dc564c..484b023a1c 100644
--- a/tests/xmconfigtest.c
+++ b/tests/xmconfigtest.c
@@ -41,7 +41,7 @@ static int
  testCompareParseXML(const char *xmcfg, const char *xml)
  {
      char *gotxmcfgData = NULL;
-    virConfPtr conf = NULL;
+    VIR_AUTOPTR(virConf) conf = NULL;
      int ret = -1;
      virConnectPtr conn = NULL;
      int wrote = 4096;
@@ -76,8 +76,6 @@ testCompareParseXML(const char *xmcfg, const char *xml)
fail:
      VIR_FREE(gotxmcfgData);
-    if (conf)
-        virConfFree(conf);
      virDomainDefFree(def);
      virObjectUnref(conn);
@@ -89,7 +87,7 @@ testCompareFormatXML(const char *xmcfg, const char *xml)
  {
      char *xmcfgData = NULL;
      char *gotxml = NULL;
-    virConfPtr conf = NULL;
+    VIR_AUTOPTR(virConf) conf = NULL;
      int ret = -1;
      virDomainDefPtr def = NULL;
@@ -111,8 +109,6 @@ testCompareFormatXML(const char *xmcfg, const char *xml)
      ret = 0;
fail:
-    if (conf)
-        virConfFree(conf);
      VIR_FREE(xmcfgData);
      VIR_FREE(gotxml);
      virDomainDefFree(def);
diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helper.c
index d062c07a27..1a621ae53c 100644
--- a/tools/virt-login-shell-helper.c
+++ b/tools/virt-login-shell-helper.c
@@ -152,7 +152,7 @@ hideErrorFunc(void *opaque ATTRIBUTE_UNUSED,
  int
  main(int argc, char **argv)
  {
-    virConfPtr conf = NULL;
+    VIR_AUTOPTR(virConf) conf = NULL;
      const char *login_shell_path = conf_file;
      pid_t cpid = -1;
      int ret = EXIT_CANCELED;
@@ -414,7 +414,6 @@ main(int argc, char **argv)
          for (i = 0; i < nfdlist; i++)
              VIR_FORCE_CLOSE(fdlist[i]);
      VIR_FREE(fdlist);
-    virConfFree(conf);
      if (dom)
          virDomainFree(dom);
      if (conn)

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux