提交 6bb4242d 编写于 作者: M Michal Privoznik

lib: Define and use autofree for virConfPtr

Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
上级 f5897820
......@@ -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
......
......@@ -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:
......
......@@ -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;
......
......@@ -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;
}
/*
......
......@@ -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;
}
......
......@@ -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 conf;
return NULL;
cleanup:
if (conf)
virConfFree(conf);
return NULL;
VIR_RETURN_PTR(conf);
}
......@@ -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 conf;
return NULL;
cleanup:
if (conf)
virConfFree(conf);
return NULL;
VIR_RETURN_PTR(conf);
}
......@@ -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);
}
......@@ -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;
}
......
......@@ -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;
......
......@@ -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);
}
......@@ -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)
......
......@@ -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;
return vmdef;
error:
virDomainDefFree(vmdef);
vmdef = NULL;
cleanup:
virConfFree(properties);
return vmdef;
return NULL;
}
......@@ -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;
ret = 0;
return -1;
cleanup:
virConfFree(conf);
return ret;
return 0;
}
......
......@@ -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);
}
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册