lib: Define and use autofree for virConfPtr

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Michal Privoznik 2019-09-09 17:56:26 +02:00
parent f5897820ca
commit 6bb4242d9f
22 changed files with 131 additions and 212 deletions

View File

@ -70,8 +70,7 @@ int
virBhyveLoadDriverConfig(virBhyveDriverConfigPtr cfg, virBhyveLoadDriverConfig(virBhyveDriverConfigPtr cfg,
const char *filename) const char *filename)
{ {
virConfPtr conf; VIR_AUTOPTR(virConf) conf = NULL;
int ret = -1;
if (access(filename, R_OK) == -1) { if (access(filename, R_OK) == -1) {
VIR_INFO("Could not read bhyve config file %s", filename); VIR_INFO("Could not read bhyve config file %s", filename);
@ -83,12 +82,9 @@ virBhyveLoadDriverConfig(virBhyveDriverConfigPtr cfg,
if (virConfGetValueString(conf, "firmware_dir", if (virConfGetValueString(conf, "firmware_dir",
&cfg->firmwareDir) < 0) &cfg->firmwareDir) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
virConfFree(conf);
return ret;
} }
virBhyveDriverConfigPtr virBhyveDriverConfigPtr

View File

@ -223,7 +223,7 @@ virAdmConnectOpen(const char *name, unsigned int flags)
char *sock_path = NULL; char *sock_path = NULL;
char *alias = NULL; char *alias = NULL;
virAdmConnectPtr conn = NULL; virAdmConnectPtr conn = NULL;
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
char *uristr = NULL; char *uristr = NULL;
if (virAdmInitialize() < 0) if (virAdmInitialize() < 0)
@ -272,7 +272,6 @@ virAdmConnectOpen(const char *name, unsigned int flags)
cleanup: cleanup:
VIR_FREE(sock_path); VIR_FREE(sock_path);
VIR_FREE(uristr); VIR_FREE(uristr);
virConfFree(conf);
return conn; return conn;
error: error:

View File

@ -859,7 +859,7 @@ virConnectOpenInternal(const char *name,
size_t i; size_t i;
int res; int res;
virConnectPtr ret; virConnectPtr ret;
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
char *uristr = NULL; char *uristr = NULL;
ret = virGetConnect(); ret = virGetConnect();
@ -1069,14 +1069,12 @@ virConnectOpenInternal(const char *name,
goto failed; goto failed;
} }
virConfFree(conf);
VIR_FREE(uristr); VIR_FREE(uristr);
return ret; return ret;
failed: failed:
VIR_FREE(uristr); VIR_FREE(uristr);
virConfFree(conf);
virObjectUnref(ret); virObjectUnref(ret);
return NULL; return NULL;

View File

@ -1864,8 +1864,7 @@ libxlDriverConfigGet(libxlDriverPrivatePtr driver)
int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg, int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
const char *filename) const char *filename)
{ {
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
int ret = -1;
/* defaults for keepalive messages */ /* defaults for keepalive messages */
cfg->keepAliveInterval = 5; cfg->keepAliveInterval = 5;
@ -1880,30 +1879,25 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
} }
if (!(conf = virConfReadFile(filename, 0))) if (!(conf = virConfReadFile(filename, 0)))
goto cleanup; return -1;
/* setup autoballoon */ /* setup autoballoon */
if (libxlGetAutoballoonConf(cfg, conf) < 0) if (libxlGetAutoballoonConf(cfg, conf) < 0)
goto cleanup; return -1;
if (virConfGetValueString(conf, "lock_manager", &cfg->lockManagerName) < 0) if (virConfGetValueString(conf, "lock_manager", &cfg->lockManagerName) < 0)
goto cleanup; return -1;
if (virConfGetValueInt(conf, "keepalive_interval", &cfg->keepAliveInterval) < 0) if (virConfGetValueInt(conf, "keepalive_interval", &cfg->keepAliveInterval) < 0)
goto cleanup; return -1;
if (virConfGetValueUInt(conf, "keepalive_count", &cfg->keepAliveCount) < 0) if (virConfGetValueUInt(conf, "keepalive_count", &cfg->keepAliveCount) < 0)
goto cleanup; return -1;
if (virConfGetValueBool(conf, "nested_hvm", &cfg->nested_hvm) < 0) if (virConfGetValueBool(conf, "nested_hvm", &cfg->nested_hvm) < 0)
goto cleanup; return -1;
ret = 0;
cleanup:
virConfFree(conf);
return ret;
return 0;
} }
/* /*

View File

@ -2675,7 +2675,7 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn,
libxlDriverPrivatePtr driver = conn->privateData; libxlDriverPrivatePtr driver = conn->privateData;
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
char *xml = NULL; char *xml = NULL;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
@ -2712,8 +2712,6 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn,
cleanup: cleanup:
virDomainDefFree(def); virDomainDefFree(def);
if (conf)
virConfFree(conf);
virObjectUnref(cfg); virObjectUnref(cfg);
return xml; return xml;
} }
@ -2727,7 +2725,7 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
libxlDriverPrivatePtr driver = conn->privateData; libxlDriverPrivatePtr driver = conn->privateData;
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
int len = MAX_CONFIG_SIZE; int len = MAX_CONFIG_SIZE;
char *ret = NULL; char *ret = NULL;
@ -2764,8 +2762,6 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
cleanup: cleanup:
virDomainDefFree(def); virDomainDefFree(def);
if (conf)
virConfFree(conf);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
} }

View File

@ -2198,52 +2198,47 @@ xenFormatXLDomainChannels(virConfPtr conf, virDomainDefPtr def)
virConfPtr virConfPtr
xenFormatXL(virDomainDefPtr def, virConnectPtr conn) xenFormatXL(virDomainDefPtr def, virConnectPtr conn)
{ {
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
if (!(conf = virConfNew())) if (!(conf = virConfNew()))
goto cleanup; return NULL;
if (xenFormatConfigCommon(conf, def, conn, XEN_CONFIG_FORMAT_XL) < 0) if (xenFormatConfigCommon(conf, def, conn, XEN_CONFIG_FORMAT_XL) < 0)
goto cleanup; return NULL;
if (xenFormatXLOS(conf, def) < 0) if (xenFormatXLOS(conf, def) < 0)
goto cleanup; return NULL;
if (xenFormatXLCPUID(conf, def) < 0) if (xenFormatXLCPUID(conf, def) < 0)
goto cleanup; return NULL;
#ifdef LIBXL_HAVE_VNUMA #ifdef LIBXL_HAVE_VNUMA
if (xenFormatXLDomainVnuma(conf, def) < 0) if (xenFormatXLDomainVnuma(conf, def) < 0)
goto cleanup; return NULL;
#endif #endif
#ifdef LIBXL_HAVE_BUILDINFO_GRANT_LIMITS #ifdef LIBXL_HAVE_BUILDINFO_GRANT_LIMITS
if (xenFormatXLGntLimits(conf, def) < 0) if (xenFormatXLGntLimits(conf, def) < 0)
goto cleanup; return NULL;
#endif #endif
if (xenFormatXLDomainDisks(conf, def) < 0) if (xenFormatXLDomainDisks(conf, def) < 0)
goto cleanup; return NULL;
if (xenFormatXLSpice(conf, def) < 0) if (xenFormatXLSpice(conf, def) < 0)
goto cleanup; return NULL;
if (xenFormatXLInputDevs(conf, def) < 0) if (xenFormatXLInputDevs(conf, def) < 0)
goto cleanup; return NULL;
if (xenFormatXLUSB(conf, def) < 0) if (xenFormatXLUSB(conf, def) < 0)
goto cleanup; return NULL;
if (xenFormatXLUSBController(conf, def) < 0) if (xenFormatXLUSBController(conf, def) < 0)
goto cleanup; return NULL;
if (xenFormatXLDomainChannels(conf, def) < 0) if (xenFormatXLDomainChannels(conf, def) < 0)
goto cleanup; return NULL;
return conf; VIR_RETURN_PTR(conf);
cleanup:
if (conf)
virConfFree(conf);
return NULL;
} }

View File

@ -599,27 +599,22 @@ virConfPtr
xenFormatXM(virConnectPtr conn, xenFormatXM(virConnectPtr conn,
virDomainDefPtr def) virDomainDefPtr def)
{ {
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
if (!(conf = virConfNew())) if (!(conf = virConfNew()))
goto cleanup; return NULL;
if (xenFormatConfigCommon(conf, def, conn, XEN_CONFIG_FORMAT_XM) < 0) if (xenFormatConfigCommon(conf, def, conn, XEN_CONFIG_FORMAT_XM) < 0)
goto cleanup; return NULL;
if (xenFormatXMOS(conf, def) < 0) if (xenFormatXMOS(conf, def) < 0)
goto cleanup; return NULL;
if (xenFormatXMDisks(conf, def) < 0) if (xenFormatXMDisks(conf, def) < 0)
goto cleanup; return NULL;
if (xenFormatXMInputDevs(conf, def) < 0) if (xenFormatXMInputDevs(conf, def) < 0)
goto cleanup; return NULL;
return conf; VIR_RETURN_PTR(conf);
cleanup:
if (conf)
virConfFree(conf);
return NULL;
} }

View File

@ -114,8 +114,7 @@ virLockDaemonConfigLoadFile(virLockDaemonConfigPtr data,
const char *filename, const char *filename,
bool allow_missing) bool allow_missing)
{ {
virConfPtr conf; VIR_AUTOPTR(virConf) conf = NULL;
int ret;
if (allow_missing && if (allow_missing &&
access(filename, R_OK) == -1 && access(filename, R_OK) == -1 &&
@ -126,7 +125,5 @@ virLockDaemonConfigLoadFile(virLockDaemonConfigPtr data,
if (!conf) if (!conf)
return -1; return -1;
ret = virLockDaemonConfigLoadOptions(data, conf); return virLockDaemonConfigLoadOptions(data, conf);
virConfFree(conf);
return ret;
} }

View File

@ -81,8 +81,7 @@ static virLockManagerLockDaemonDriverPtr driver;
static int virLockManagerLockDaemonLoadConfig(const char *configFile) static int virLockManagerLockDaemonLoadConfig(const char *configFile)
{ {
virConfPtr conf; VIR_AUTOPTR(virConf) conf = NULL;
int ret = -1;
if (access(configFile, R_OK) == -1) { if (access(configFile, R_OK) == -1) {
if (errno != ENOENT) { if (errno != ENOENT) {
@ -98,25 +97,22 @@ static int virLockManagerLockDaemonLoadConfig(const char *configFile)
return -1; return -1;
if (virConfGetValueBool(conf, "auto_disk_leases", &driver->autoDiskLease) < 0) if (virConfGetValueBool(conf, "auto_disk_leases", &driver->autoDiskLease) < 0)
goto cleanup; return -1;
if (virConfGetValueString(conf, "file_lockspace_dir", &driver->fileLockSpaceDir) < 0) if (virConfGetValueString(conf, "file_lockspace_dir", &driver->fileLockSpaceDir) < 0)
goto cleanup; return -1;
if (virConfGetValueString(conf, "lvm_lockspace_dir", &driver->lvmLockSpaceDir) < 0) if (virConfGetValueString(conf, "lvm_lockspace_dir", &driver->lvmLockSpaceDir) < 0)
goto cleanup; return -1;
if (virConfGetValueString(conf, "scsi_lockspace_dir", &driver->scsiLockSpaceDir) < 0) if (virConfGetValueString(conf, "scsi_lockspace_dir", &driver->scsiLockSpaceDir) < 0)
goto cleanup; return -1;
driver->requireLeaseForDisks = !driver->autoDiskLease; driver->requireLeaseForDisks = !driver->autoDiskLease;
if (virConfGetValueBool(conf, "require_lease_for_disks", &driver->requireLeaseForDisks) < 0) if (virConfGetValueBool(conf, "require_lease_for_disks", &driver->requireLeaseForDisks) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
virConfFree(conf);
return ret;
} }

View File

@ -119,7 +119,7 @@ static int
virLockManagerSanlockLoadConfig(virLockManagerSanlockDriverPtr driver, virLockManagerSanlockLoadConfig(virLockManagerSanlockDriverPtr driver,
const char *configFile) const char *configFile)
{ {
virConfPtr conf; VIR_AUTOPTR(virConf) conf = NULL;
int ret = -1; int ret = -1;
char *user = NULL; char *user = NULL;
char *group = NULL; char *group = NULL;
@ -167,7 +167,6 @@ virLockManagerSanlockLoadConfig(virLockManagerSanlockDriverPtr driver,
ret = 0; ret = 0;
cleanup: cleanup:
virConfFree(conf);
VIR_FREE(user); VIR_FREE(user);
VIR_FREE(group); VIR_FREE(group);
return ret; return ret;

View File

@ -120,8 +120,7 @@ virLogDaemonConfigLoadFile(virLogDaemonConfigPtr data,
const char *filename, const char *filename,
bool allow_missing) bool allow_missing)
{ {
virConfPtr conf; VIR_AUTOPTR(virConf) conf = NULL;
int ret;
if (allow_missing && if (allow_missing &&
access(filename, R_OK) == -1 && access(filename, R_OK) == -1 &&
@ -132,7 +131,5 @@ virLogDaemonConfigLoadFile(virLogDaemonConfigPtr data,
if (!conf) if (!conf)
return -1; return -1;
ret = virLogDaemonConfigLoadOptions(data, conf); return virLogDaemonConfigLoadOptions(data, conf);
virConfFree(conf);
return ret;
} }

View File

@ -252,8 +252,7 @@ int
virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg, virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg,
const char *filename) const char *filename)
{ {
virConfPtr conf; VIR_AUTOPTR(virConf) conf = NULL;
int ret = -1;
/* Avoid error from non-existent or unreadable file. */ /* Avoid error from non-existent or unreadable file. */
if (access(filename, R_OK) == -1) if (access(filename, R_OK) == -1)
@ -264,21 +263,18 @@ virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg,
return -1; return -1;
if (virConfGetValueBool(conf, "log_with_libvirtd", &cfg->log_libvirtd) < 0) if (virConfGetValueBool(conf, "log_with_libvirtd", &cfg->log_libvirtd) < 0)
goto cleanup; return -1;
if (virConfGetValueString(conf, "security_driver", &cfg->securityDriverName) < 0) if (virConfGetValueString(conf, "security_driver", &cfg->securityDriverName) < 0)
goto cleanup; return -1;
if (virConfGetValueBool(conf, "security_default_confined", &cfg->securityDefaultConfined) < 0) if (virConfGetValueBool(conf, "security_default_confined", &cfg->securityDefaultConfined) < 0)
goto cleanup; return -1;
if (virConfGetValueBool(conf, "security_require_confined", &cfg->securityRequireConfined) < 0) if (virConfGetValueBool(conf, "security_require_confined", &cfg->securityRequireConfined) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
virConfFree(conf);
return ret;
} }
virLXCDriverConfigPtr virLXCDriverGetConfig(virLXCDriverPtr driver) virLXCDriverConfigPtr virLXCDriverGetConfig(virLXCDriverPtr driver)

View File

@ -1079,7 +1079,7 @@ lxcParseConfigString(const char *config,
virDomainXMLOptionPtr xmlopt) virDomainXMLOptionPtr xmlopt)
{ {
virDomainDefPtr vmdef = NULL; virDomainDefPtr vmdef = NULL;
virConfPtr properties = NULL; VIR_AUTOPTR(virConf) properties = NULL;
VIR_AUTOFREE(char *) value = NULL; VIR_AUTOFREE(char *) value = NULL;
if (!(properties = virConfReadString(config, VIR_CONF_FLAG_LXC_FORMAT))) if (!(properties = virConfReadString(config, VIR_CONF_FLAG_LXC_FORMAT)))
@ -1192,14 +1192,9 @@ lxcParseConfigString(const char *config,
xmlopt, NULL) < 0) xmlopt, NULL) < 0)
goto error; goto error;
goto cleanup; return vmdef;
error: error:
virDomainDefFree(vmdef); virDomainDefFree(vmdef);
vmdef = NULL; return NULL;
cleanup:
virConfFree(properties);
return vmdef;
} }

View File

@ -1000,8 +1000,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
const char *filename, const char *filename,
bool privileged) bool privileged)
{ {
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
int ret = -1;
/* Just check the file is readable before opening it, otherwise /* Just check the file is readable before opening it, otherwise
* libvirt emits an error. * libvirt emits an error.
@ -1012,67 +1011,63 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
} }
if (!(conf = virConfReadFile(filename, 0))) if (!(conf = virConfReadFile(filename, 0)))
goto cleanup; return -1;
if (virQEMUDriverConfigLoadDefaultTLSEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadDefaultTLSEntry(cfg, conf) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadVNCEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadVNCEntry(cfg, conf) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadNographicsEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadNographicsEntry(cfg, conf) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadSPICEEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadSPICEEntry(cfg, conf) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadSpecificTLSEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadSpecificTLSEntry(cfg, conf) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadRemoteDisplayEntry(cfg, conf, filename) < 0) if (virQEMUDriverConfigLoadRemoteDisplayEntry(cfg, conf, filename) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadSaveEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadSaveEntry(cfg, conf) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadProcessEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadProcessEntry(cfg, conf) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadDeviceEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadDeviceEntry(cfg, conf) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadRPCEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadRPCEntry(cfg, conf) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadNetworkEntry(cfg, conf, filename) < 0) if (virQEMUDriverConfigLoadNetworkEntry(cfg, conf, filename) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadLogEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadLogEntry(cfg, conf) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadNVRAMEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadNVRAMEntry(cfg, conf) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadGlusterDebugEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadGlusterDebugEntry(cfg, conf) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadSecurityEntry(cfg, conf, privileged) < 0) if (virQEMUDriverConfigLoadSecurityEntry(cfg, conf, privileged) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadMemoryEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadMemoryEntry(cfg, conf) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadSWTPMEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadSWTPMEntry(cfg, conf) < 0)
goto cleanup; return -1;
if (virQEMUDriverConfigLoadCapsFiltersEntry(cfg, conf) < 0) if (virQEMUDriverConfigLoadCapsFiltersEntry(cfg, conf) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
virConfFree(conf);
return ret;
} }

View File

@ -401,8 +401,7 @@ daemonConfigLoadFile(struct daemonConfig *data,
const char *filename, const char *filename,
bool allow_missing) bool allow_missing)
{ {
virConfPtr conf; VIR_AUTOPTR(virConf) conf = NULL;
int ret;
if (allow_missing && if (allow_missing &&
access(filename, R_OK) == -1 && access(filename, R_OK) == -1 &&
@ -413,23 +412,18 @@ daemonConfigLoadFile(struct daemonConfig *data,
if (!conf) if (!conf)
return -1; return -1;
ret = daemonConfigLoadOptions(data, filename, conf); return daemonConfigLoadOptions(data, filename, conf);
virConfFree(conf);
return ret;
} }
int daemonConfigLoadData(struct daemonConfig *data, int daemonConfigLoadData(struct daemonConfig *data,
const char *filename, const char *filename,
const char *filedata) const char *filedata)
{ {
virConfPtr conf; VIR_AUTOPTR(virConf) conf = NULL;
int ret;
conf = virConfReadString(filedata, 0); conf = virConfReadString(filedata, 0);
if (!conf) if (!conf)
return -1; return -1;
ret = daemonConfigLoadOptions(data, filename, conf); return daemonConfigLoadOptions(data, filename, conf);
virConfFree(conf);
return ret;
} }

View File

@ -635,7 +635,7 @@ virSecuritySELinuxGenNewContext(const char *basecontext,
static int static int
virSecuritySELinuxLXCInitialize(virSecurityManagerPtr mgr) virSecuritySELinuxLXCInitialize(virSecurityManagerPtr mgr)
{ {
virConfPtr selinux_conf; VIR_AUTOPTR(virConf) selinux_conf = NULL;
virSecuritySELinuxDataPtr data = virSecurityManagerGetPrivateData(mgr); virSecuritySELinuxDataPtr data = virSecurityManagerGetPrivateData(mgr);
data->skipAllLabel = true; data->skipAllLabel = true;
@ -685,7 +685,6 @@ virSecuritySELinuxLXCInitialize(virSecurityManagerPtr mgr)
if (!(data->mcs = virHashCreate(10, NULL))) if (!(data->mcs = virHashCreate(10, NULL)))
goto error; goto error;
virConfFree(selinux_conf);
return 0; return 0;
error: error:
@ -693,7 +692,6 @@ virSecuritySELinuxLXCInitialize(virSecurityManagerPtr mgr)
selabel_close(data->label_handle); selabel_close(data->label_handle);
data->label_handle = NULL; data->label_handle = NULL;
# endif # endif
virConfFree(selinux_conf);
VIR_FREE(data->domain_context); VIR_FREE(data->domain_context);
VIR_FREE(data->file_context); VIR_FREE(data->file_context);
VIR_FREE(data->content_context); VIR_FREE(data->content_context);

View File

@ -22,6 +22,7 @@
#include "virutil.h" #include "virutil.h"
#include "virenum.h" #include "virenum.h"
#include "virautoclean.h"
/** /**
* virConfType: * virConfType:
@ -80,6 +81,7 @@ virConfPtr virConfReadFile(const char *filename, unsigned int flags);
virConfPtr virConfReadString(const char *memory, virConfPtr virConfReadString(const char *memory,
unsigned int flags); unsigned int flags);
int virConfFree(virConfPtr conf); int virConfFree(virConfPtr conf);
VIR_DEFINE_AUTOPTR_FUNC(virConf, virConfFree);
void virConfFreeValue(virConfValuePtr val); void virConfFreeValue(virConfValuePtr val);
virConfValuePtr virConfGetValue(virConfPtr conf, virConfValuePtr virConfGetValue(virConfPtr conf,
const char *setting); const char *setting);

View File

@ -1275,7 +1275,7 @@ virVMXParseConfig(virVMXContext *ctx,
const char *vmx) const char *vmx)
{ {
bool success = false; bool success = false;
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
char *encoding = NULL; char *encoding = NULL;
char *utf8; char *utf8;
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
@ -1850,7 +1850,6 @@ virVMXParseConfig(virVMXContext *ctx,
def = NULL; def = NULL;
} }
virConfFree(conf);
VIR_FREE(encoding); VIR_FREE(encoding);
VIR_FREE(sched_cpu_affinity); VIR_FREE(sched_cpu_affinity);
VIR_FREE(sched_cpu_shares); VIR_FREE(sched_cpu_shares);

View File

@ -33,7 +33,7 @@ static int testConfRoundTrip(const void *opaque)
{ {
const char *name = opaque; const char *name = opaque;
int ret = -1; int ret = -1;
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
int len = 10000; int len = 10000;
char *buffer = NULL; char *buffer = NULL;
char *srcfile = NULL; char *srcfile = NULL;
@ -68,7 +68,6 @@ static int testConfRoundTrip(const void *opaque)
VIR_FREE(srcfile); VIR_FREE(srcfile);
VIR_FREE(dstfile); VIR_FREE(dstfile);
VIR_FREE(buffer); VIR_FREE(buffer);
virConfFree(conf);
return ret; return ret;
} }
@ -80,7 +79,7 @@ static int testConfMemoryNoNewline(const void *opaque ATTRIBUTE_UNUSED)
"string = 'foo'\n" \ "string = 'foo'\n" \
"uint = 12345"; "uint = 12345";
virConfPtr conf = virConfReadString(srcdata, 0); VIR_AUTOPTR(virConf) conf = virConfReadString(srcdata, 0);
int ret = -1; int ret = -1;
virConfValuePtr val; virConfValuePtr val;
unsigned long long llvalue; unsigned long long llvalue;
@ -134,7 +133,6 @@ static int testConfMemoryNoNewline(const void *opaque ATTRIBUTE_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(str); VIR_FREE(str);
virConfFree(conf);
return ret; return ret;
} }
@ -150,8 +148,7 @@ static int testConfParseInt(const void *opaque ATTRIBUTE_UNUSED)
"ssize_t = -87539319\n" \ "ssize_t = -87539319\n" \
"string = \"foo\"\n"; "string = \"foo\"\n";
int ret = -1; VIR_AUTOPTR(virConf) conf = virConfReadString(srcdata, 0);
virConfPtr conf = virConfReadString(srcdata, 0);
int iv; int iv;
unsigned int ui; unsigned int ui;
size_t s; size_t s;
@ -165,40 +162,40 @@ static int testConfParseInt(const void *opaque ATTRIBUTE_UNUSED)
if (virConfGetValueType(conf, "int") != if (virConfGetValueType(conf, "int") !=
VIR_CONF_LLONG) { VIR_CONF_LLONG) {
fprintf(stderr, "expected a long for 'int'\n"); fprintf(stderr, "expected a long for 'int'\n");
goto cleanup; return -1;
} }
if (virConfGetValueInt(conf, "int", &iv) < 0) if (virConfGetValueInt(conf, "int", &iv) < 0)
goto cleanup; return -1;
if (iv != -1729) { if (iv != -1729) {
fprintf(stderr, "Expected -1729 got %d\n", iv); fprintf(stderr, "Expected -1729 got %d\n", iv);
goto cleanup; return -1;
} }
if (virConfGetValueInt(conf, "string", &iv) != -1) { if (virConfGetValueInt(conf, "string", &iv) != -1) {
fprintf(stderr, "Expected error for 'string' param\n"); fprintf(stderr, "Expected error for 'string' param\n");
goto cleanup; return -1;
} }
if (virConfGetValueType(conf, "uint") != if (virConfGetValueType(conf, "uint") !=
VIR_CONF_ULLONG) { VIR_CONF_ULLONG) {
fprintf(stderr, "expected a unsigned long for 'uint'\n"); fprintf(stderr, "expected a unsigned long for 'uint'\n");
goto cleanup; return -1;
} }
if (virConfGetValueUInt(conf, "uint", &ui) < 0) if (virConfGetValueUInt(conf, "uint", &ui) < 0)
goto cleanup; return -1;
if (ui != 1729) { if (ui != 1729) {
fprintf(stderr, "Expected 1729 got %u\n", ui); fprintf(stderr, "Expected 1729 got %u\n", ui);
goto cleanup; return -1;
} }
if (virConfGetValueUInt(conf, "string", &ui) != -1) { if (virConfGetValueUInt(conf, "string", &ui) != -1) {
fprintf(stderr, "Expected error for 'string' param\n"); 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") != if (virConfGetValueType(conf, "llong") !=
VIR_CONF_LLONG) { VIR_CONF_LLONG) {
fprintf(stderr, "expected a long for 'llong'\n"); fprintf(stderr, "expected a long for 'llong'\n");
goto cleanup; return -1;
} }
if (virConfGetValueLLong(conf, "llong", &l) < 0) if (virConfGetValueLLong(conf, "llong", &l) < 0)
goto cleanup; return -1;
if (l != -6963472309248) { if (l != -6963472309248) {
fprintf(stderr, "Expected -6963472309248 got %lld\n", l); fprintf(stderr, "Expected -6963472309248 got %lld\n", l);
goto cleanup; return -1;
} }
if (virConfGetValueLLong(conf, "string", &l) != -1) { if (virConfGetValueLLong(conf, "string", &l) != -1) {
fprintf(stderr, "Expected error for 'string' param\n"); 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") != if (virConfGetValueType(conf, "ullong") !=
VIR_CONF_ULLONG) { VIR_CONF_ULLONG) {
fprintf(stderr, "expected a unsigned long for 'ullong'\n"); fprintf(stderr, "expected a unsigned long for 'ullong'\n");
goto cleanup; return -1;
} }
if (virConfGetValueULLong(conf, "ullong", &ul) < 0) if (virConfGetValueULLong(conf, "ullong", &ul) < 0)
goto cleanup; return -1;
if (ul != 6963472309248) { if (ul != 6963472309248) {
fprintf(stderr, "Expected 6963472309248 got %llu\n", ul); fprintf(stderr, "Expected 6963472309248 got %llu\n", ul);
goto cleanup; return -1;
} }
if (virConfGetValueULLong(conf, "string", &ul) != -1) { if (virConfGetValueULLong(conf, "string", &ul) != -1) {
fprintf(stderr, "Expected error for 'string' param\n"); 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") != if (virConfGetValueType(conf, "size_t") !=
VIR_CONF_ULLONG) { VIR_CONF_ULLONG) {
fprintf(stderr, "expected a unsigned long for 'size_T'\n"); fprintf(stderr, "expected a unsigned long for 'size_T'\n");
goto cleanup; return -1;
} }
if (virConfGetValueSizeT(conf, "size_t", &s) < 0) if (virConfGetValueSizeT(conf, "size_t", &s) < 0)
goto cleanup; return -1;
if (s != 87539319) { if (s != 87539319) {
fprintf(stderr, "Expected 87539319 got %zu\n", s); fprintf(stderr, "Expected 87539319 got %zu\n", s);
goto cleanup; return -1;
} }
if (virConfGetValueSizeT(conf, "string", &s) != -1) { if (virConfGetValueSizeT(conf, "string", &s) != -1) {
fprintf(stderr, "Expected error for 'string' param\n"); 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") != if (virConfGetValueType(conf, "ssize_t") !=
VIR_CONF_LLONG) { VIR_CONF_LLONG) {
fprintf(stderr, "expected a unsigned long for 'ssize_t'\n"); fprintf(stderr, "expected a unsigned long for 'ssize_t'\n");
goto cleanup; return -1;
} }
if (virConfGetValueSSizeT(conf, "ssize_t", &ss) < 0) if (virConfGetValueSSizeT(conf, "ssize_t", &ss) < 0)
goto cleanup; return -1;
if (ss != -87539319) { if (ss != -87539319) {
fprintf(stderr, "Expected -87539319 got %zd\n", ss); fprintf(stderr, "Expected -87539319 got %zd\n", ss);
goto cleanup; return -1;
} }
if (virConfGetValueSSizeT(conf, "string", &ss) != -1) { if (virConfGetValueSSizeT(conf, "string", &ss) != -1) {
fprintf(stderr, "Expected error for 'string' param\n"); fprintf(stderr, "Expected error for 'string' param\n");
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
virConfFree(conf);
return ret;
} }
static int testConfParseBool(const void *opaque ATTRIBUTE_UNUSED) static int testConfParseBool(const void *opaque ATTRIBUTE_UNUSED)
@ -299,8 +293,7 @@ static int testConfParseBool(const void *opaque ATTRIBUTE_UNUSED)
"int = 6963472309248\n" \ "int = 6963472309248\n" \
"string = \"foo\"\n"; "string = \"foo\"\n";
int ret = -1; VIR_AUTOPTR(virConf) conf = virConfReadString(srcdata, 0);
virConfPtr conf = virConfReadString(srcdata, 0);
bool f = true; bool f = true;
bool t = false; bool t = false;
@ -310,15 +303,15 @@ static int testConfParseBool(const void *opaque ATTRIBUTE_UNUSED)
if (virConfGetValueType(conf, "false") != if (virConfGetValueType(conf, "false") !=
VIR_CONF_ULLONG) { VIR_CONF_ULLONG) {
fprintf(stderr, "expected a long for 'false'\n"); fprintf(stderr, "expected a long for 'false'\n");
goto cleanup; return -1;
} }
if (virConfGetValueBool(conf, "false", &f) < 0) if (virConfGetValueBool(conf, "false", &f) < 0)
goto cleanup; return -1;
if (f != false) { if (f != false) {
fprintf(stderr, "Expected 0 got %d\n", f); 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") != if (virConfGetValueType(conf, "true") !=
VIR_CONF_ULLONG) { VIR_CONF_ULLONG) {
fprintf(stderr, "expected a long for 'true'\n"); fprintf(stderr, "expected a long for 'true'\n");
goto cleanup; return -1;
} }
if (virConfGetValueBool(conf, "true", &t) < 0) if (virConfGetValueBool(conf, "true", &t) < 0)
goto cleanup; return -1;
if (t != true) { if (t != true) {
fprintf(stderr, "Expected 1 got %d\n", t); fprintf(stderr, "Expected 1 got %d\n", t);
goto cleanup; return -1;
} }
if (virConfGetValueBool(conf, "int", &t) != -1) { if (virConfGetValueBool(conf, "int", &t) != -1) {
fprintf(stderr, "Expected error for 'string' param\n"); fprintf(stderr, "Expected error for 'string' param\n");
goto cleanup; return -1;
} }
if (virConfGetValueBool(conf, "string", &t) != -1) { if (virConfGetValueBool(conf, "string", &t) != -1) {
fprintf(stderr, "Expected error for 'string' param\n"); fprintf(stderr, "Expected error for 'string' param\n");
goto cleanup; return -1;
} }
return 0;
ret = 0;
cleanup:
virConfFree(conf);
return ret;
} }
@ -364,7 +353,7 @@ static int testConfParseString(const void *opaque ATTRIBUTE_UNUSED)
"string = \"foo\"\n"; "string = \"foo\"\n";
int ret = -1; int ret = -1;
virConfPtr conf = virConfReadString(srcdata, 0); VIR_AUTOPTR(virConf) conf = virConfReadString(srcdata, 0);
char *str = NULL; char *str = NULL;
if (!conf) if (!conf)
@ -392,7 +381,6 @@ static int testConfParseString(const void *opaque ATTRIBUTE_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(str); VIR_FREE(str);
virConfFree(conf);
return ret; return ret;
} }
@ -404,7 +392,7 @@ static int testConfParseStringList(const void *opaque ATTRIBUTE_UNUSED)
"string = \"foo\"\n"; "string = \"foo\"\n";
int ret = -1; int ret = -1;
virConfPtr conf = virConfReadString(srcdata, 0); VIR_AUTOPTR(virConf) conf = virConfReadString(srcdata, 0);
char **str = NULL; char **str = NULL;
if (!conf) if (!conf)
@ -457,7 +445,6 @@ static int testConfParseStringList(const void *opaque ATTRIBUTE_UNUSED)
ret = 0; ret = 0;
cleanup: cleanup:
virStringListFree(str); virStringListFree(str);
virConfFree(conf);
return ret; return ret;
} }

View File

@ -68,7 +68,7 @@ static int
testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars) testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
{ {
char *gotxlcfgData = NULL; char *gotxlcfgData = NULL;
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
virConnectPtr conn = NULL; virConnectPtr conn = NULL;
int wrote = 4096; int wrote = 4096;
int ret = -1; int ret = -1;
@ -113,8 +113,6 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
fail: fail:
VIR_FREE(replacedXML); VIR_FREE(replacedXML);
VIR_FREE(gotxlcfgData); VIR_FREE(gotxlcfgData);
if (conf)
virConfFree(conf);
virDomainDefFree(def); virDomainDefFree(def);
virObjectUnref(conn); virObjectUnref(conn);
@ -130,7 +128,7 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
{ {
char *xlcfgData = NULL; char *xlcfgData = NULL;
char *gotxml = NULL; char *gotxml = NULL;
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
int ret = -1; int ret = -1;
virConnectPtr conn; virConnectPtr conn;
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
@ -165,8 +163,6 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
ret = 0; ret = 0;
fail: fail:
if (conf)
virConfFree(conf);
VIR_FREE(replacedXML); VIR_FREE(replacedXML);
VIR_FREE(xlcfgData); VIR_FREE(xlcfgData);
VIR_FREE(gotxml); VIR_FREE(gotxml);

View File

@ -41,7 +41,7 @@ static int
testCompareParseXML(const char *xmcfg, const char *xml) testCompareParseXML(const char *xmcfg, const char *xml)
{ {
char *gotxmcfgData = NULL; char *gotxmcfgData = NULL;
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
int ret = -1; int ret = -1;
virConnectPtr conn = NULL; virConnectPtr conn = NULL;
int wrote = 4096; int wrote = 4096;
@ -76,8 +76,6 @@ testCompareParseXML(const char *xmcfg, const char *xml)
fail: fail:
VIR_FREE(gotxmcfgData); VIR_FREE(gotxmcfgData);
if (conf)
virConfFree(conf);
virDomainDefFree(def); virDomainDefFree(def);
virObjectUnref(conn); virObjectUnref(conn);
@ -89,7 +87,7 @@ testCompareFormatXML(const char *xmcfg, const char *xml)
{ {
char *xmcfgData = NULL; char *xmcfgData = NULL;
char *gotxml = NULL; char *gotxml = NULL;
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
int ret = -1; int ret = -1;
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
@ -111,8 +109,6 @@ testCompareFormatXML(const char *xmcfg, const char *xml)
ret = 0; ret = 0;
fail: fail:
if (conf)
virConfFree(conf);
VIR_FREE(xmcfgData); VIR_FREE(xmcfgData);
VIR_FREE(gotxml); VIR_FREE(gotxml);
virDomainDefFree(def); virDomainDefFree(def);

View File

@ -152,7 +152,7 @@ hideErrorFunc(void *opaque ATTRIBUTE_UNUSED,
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
virConfPtr conf = NULL; VIR_AUTOPTR(virConf) conf = NULL;
const char *login_shell_path = conf_file; const char *login_shell_path = conf_file;
pid_t cpid = -1; pid_t cpid = -1;
int ret = EXIT_CANCELED; int ret = EXIT_CANCELED;
@ -414,7 +414,6 @@ main(int argc, char **argv)
for (i = 0; i < nfdlist; i++) for (i = 0; i < nfdlist; i++)
VIR_FORCE_CLOSE(fdlist[i]); VIR_FORCE_CLOSE(fdlist[i]);
VIR_FREE(fdlist); VIR_FREE(fdlist);
virConfFree(conf);
if (dom) if (dom)
virDomainFree(dom); virDomainFree(dom);
if (conn) if (conn)