Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> Reviewed-by: Erik Skultety <eskultet@xxxxxxxxxx> --- src/conf/domain_conf.c | 3 +-- src/conf/storage_conf.c | 3 +-- src/conf/storage_conf.h | 1 + src/conf/virstorageobj.c | 27 +++++++++++---------------- src/phyp/phyp_driver.c | 3 +-- src/storage/storage_driver.c | 6 ++---- src/test/test_driver.c | 6 ++---- tests/storagebackendsheepdogtest.c | 6 ++---- tests/storagepoolxml2xmltest.c | 3 +-- tests/storagevolxml2argvtest.c | 3 +-- tests/storagevolxml2xmltest.c | 3 +-- 11 files changed, 24 insertions(+), 40 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2b1389035e..9e46cf721b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30988,12 +30988,12 @@ int virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def) { virConnectPtr conn = NULL; - virStoragePoolDefPtr pooldef = NULL; virStoragePoolPtr pool = NULL; virStorageVolPtr vol = NULL; char *poolxml = NULL; virStorageVolInfo info; int ret = -1; + VIR_AUTOPTR(virStoragePoolDef) pooldef = NULL; if (def->src->type != VIR_STORAGE_TYPE_VOLUME) return 0; @@ -31152,7 +31152,6 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr def) virObjectUnref(pool); virObjectUnref(vol); VIR_FREE(poolxml); - virStoragePoolDefFree(pooldef); return ret; } diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 4a52b1497b..177ea63076 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -737,12 +737,12 @@ virStoragePoolDefPtr virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) { virStoragePoolOptionsPtr options; - virStoragePoolDefPtr def; virStoragePoolDefPtr ret = NULL; xmlNodePtr source_node; char *type = NULL; char *uuid = NULL; char *target_path = NULL; + VIR_AUTOPTR(virStoragePoolDef) def = NULL; if (VIR_ALLOC(def) < 0) return NULL; @@ -883,7 +883,6 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) VIR_STEAL_PTR(ret, def); cleanup: - virStoragePoolDefFree(def); VIR_FREE(uuid); VIR_FREE(type); VIR_FREE(target_path); diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index b8e73864c4..daf6f9b68c 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -461,6 +461,7 @@ VIR_ENUM_DECL(virStoragePartedFs); VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE) VIR_DEFINE_AUTOPTR_FUNC(virStoragePoolSource, virStoragePoolSourceFree); +VIR_DEFINE_AUTOPTR_FUNC(virStoragePoolDef, virStoragePoolDefFree); VIR_DEFINE_AUTOPTR_FUNC(virStorageVolDef, virStorageVolDefFree); #endif /* LIBVIRT_STORAGE_CONF_H */ diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 7005de3c24..2286857acf 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -1579,8 +1579,8 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools, const char *path, const char *autostartLink) { - virStoragePoolDefPtr def; virStoragePoolObjPtr obj; + VIR_AUTOPTR(virStoragePoolDef) def = NULL; if (!(def = virStoragePoolDefParseFile(path))) return NULL; @@ -1590,14 +1590,12 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools, _("Storage pool config filename '%s' does " "not match pool name '%s'"), path, def->name); - virStoragePoolDefFree(def); return NULL; } - if (!(obj = virStoragePoolObjAssignDef(pools, def, false))) { - virStoragePoolDefFree(def); + if (!(obj = virStoragePoolObjAssignDef(pools, def, false))) return NULL; - } + def = NULL; VIR_FREE(obj->configFile); /* for driver reload */ if (VIR_STRDUP(obj->configFile, path) < 0) { @@ -1625,39 +1623,40 @@ virStoragePoolObjLoadState(virStoragePoolObjListPtr pools, const char *name) { char *stateFile = NULL; - virStoragePoolDefPtr def = NULL; virStoragePoolObjPtr obj = NULL; xmlDocPtr xml = NULL; xmlXPathContextPtr ctxt = NULL; xmlNodePtr node = NULL; + VIR_AUTOPTR(virStoragePoolDef) def = NULL; if (!(stateFile = virFileBuildPath(stateDir, name, ".xml"))) - goto error; + return NULL; if (!(xml = virXMLParseCtxt(stateFile, NULL, _("(pool state)"), &ctxt))) - goto error; + goto cleanup; if (!(node = virXPathNode("//pool", ctxt))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not find any 'pool' element in state file")); - goto error; + goto cleanup; } ctxt->node = node; if (!(def = virStoragePoolDefParseXML(ctxt))) - goto error; + goto cleanup; if (STRNEQ(name, def->name)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Storage pool state file '%s' does not match " "pool name '%s'"), stateFile, def->name); - goto error; + goto cleanup; } /* create the object */ if (!(obj = virStoragePoolObjAssignDef(pools, def, true))) - goto error; + goto cleanup; + def = NULL; /* XXX: future handling of some additional useful status data, * for now, if a status file for a pool exists, the pool will be marked @@ -1671,10 +1670,6 @@ virStoragePoolObjLoadState(virStoragePoolObjListPtr pools, xmlFreeDoc(xml); xmlXPathFreeContext(ctxt); return obj; - - error: - virStoragePoolDefFree(def); - goto cleanup; } diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index cac5642afd..dc082b1d08 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1952,11 +1952,11 @@ phypStorageVolCreateXML(virStoragePoolPtr pool, { virCheckFlags(0, NULL); - virStoragePoolDefPtr spdef = NULL; virStorageVolPtr vol = NULL; virStorageVolPtr dup_vol = NULL; char *key = NULL; VIR_AUTOPTR(virStorageVolDef) voldef = NULL; + VIR_AUTOPTR(virStoragePoolDef) spdef = NULL; if (VIR_ALLOC(spdef) < 0) return NULL; @@ -2036,7 +2036,6 @@ phypStorageVolCreateXML(virStoragePoolPtr pool, err: VIR_FREE(key); - virStoragePoolDefFree(spdef); virObjectUnref(vol); return NULL; } diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index c50a8ef5d4..c684f44475 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -690,7 +690,6 @@ storagePoolCreateXML(virConnectPtr conn, const char *xml, unsigned int flags) { - virStoragePoolDefPtr newDef; virStoragePoolObjPtr obj = NULL; virStoragePoolDefPtr def; virStoragePoolPtr pool = NULL; @@ -698,6 +697,7 @@ storagePoolCreateXML(virConnectPtr conn, virObjectEventPtr event = NULL; char *stateFile = NULL; unsigned int build_flags = 0; + VIR_AUTOPTR(virStoragePoolDef) newDef = NULL; virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD | VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE | @@ -762,7 +762,6 @@ storagePoolCreateXML(virConnectPtr conn, cleanup: VIR_FREE(stateFile); - virStoragePoolDefFree(newDef); virObjectEventStateQueue(driver->storageEventState, event); virStoragePoolObjEndAPI(&obj); return pool; @@ -779,11 +778,11 @@ storagePoolDefineXML(virConnectPtr conn, const char *xml, unsigned int flags) { - virStoragePoolDefPtr newDef; virStoragePoolObjPtr obj = NULL; virStoragePoolDefPtr def; virStoragePoolPtr pool = NULL; virObjectEventPtr event = NULL; + VIR_AUTOPTR(virStoragePoolDef) newDef = NULL; virCheckFlags(0, NULL); @@ -822,7 +821,6 @@ storagePoolDefineXML(virConnectPtr conn, cleanup: virObjectEventStateQueue(driver->storageEventState, event); - virStoragePoolDefFree(newDef); virStoragePoolObjEndAPI(&obj); return pool; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index f07a075755..df10a02bbc 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4474,11 +4474,11 @@ testStoragePoolCreateXML(virConnectPtr conn, unsigned int flags) { testDriverPtr privconn = conn->privateData; - virStoragePoolDefPtr newDef; virStoragePoolObjPtr obj = NULL; virStoragePoolDefPtr def; virStoragePoolPtr pool = NULL; virObjectEventPtr event = NULL; + VIR_AUTOPTR(virStoragePoolDef) newDef = NULL; virCheckFlags(0, NULL); @@ -4527,7 +4527,6 @@ testStoragePoolCreateXML(virConnectPtr conn, pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); cleanup: - virStoragePoolDefFree(newDef); virObjectEventStateQueue(privconn->eventState, event); virStoragePoolObjEndAPI(&obj); virObjectUnlock(privconn); @@ -4541,11 +4540,11 @@ testStoragePoolDefineXML(virConnectPtr conn, unsigned int flags) { testDriverPtr privconn = conn->privateData; - virStoragePoolDefPtr newDef; virStoragePoolObjPtr obj = NULL; virStoragePoolDefPtr def; virStoragePoolPtr pool = NULL; virObjectEventPtr event = NULL; + VIR_AUTOPTR(virStoragePoolDef) newDef = NULL; virCheckFlags(0, NULL); @@ -4576,7 +4575,6 @@ testStoragePoolDefineXML(virConnectPtr conn, pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL); cleanup: - virStoragePoolDefFree(newDef); virObjectEventStateQueue(privconn->eventState, event); virStoragePoolObjEndAPI(&obj); virObjectUnlock(privconn); diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheepdogtest.c index 540f89c3ab..03ddf76d65 100644 --- a/tests/storagebackendsheepdogtest.c +++ b/tests/storagebackendsheepdogtest.c @@ -59,7 +59,7 @@ test_node_info_parser(const void *opaque) collie_test test = data->data; int ret = -1; char *output = NULL; - virStoragePoolDefPtr pool = NULL; + VIR_AUTOPTR(virStoragePoolDef) pool = NULL; if (!(pool = virStoragePoolDefParseFile(data->poolxml))) goto cleanup; @@ -82,7 +82,6 @@ test_node_info_parser(const void *opaque) cleanup: VIR_FREE(output); - virStoragePoolDefFree(pool); return ret; } @@ -93,7 +92,7 @@ test_vdi_list_parser(const void *opaque) collie_test test = data->data; int ret = -1; char *output = NULL; - virStoragePoolDefPtr pool = NULL; + VIR_AUTOPTR(virStoragePoolDef) pool = NULL; VIR_AUTOPTR(virStorageVolDef) vol = NULL; if (!(pool = virStoragePoolDefParseFile(data->poolxml))) @@ -120,7 +119,6 @@ test_vdi_list_parser(const void *opaque) cleanup: VIR_FREE(output); - virStoragePoolDefFree(pool); return ret; } diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index acb15f3a2c..c8d5c41cd4 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -20,7 +20,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml) { char *actual = NULL; int ret = -1; - virStoragePoolDefPtr dev = NULL; + VIR_AUTOPTR(virStoragePoolDef) dev = NULL; if (!(dev = virStoragePoolDefParseFile(inxml))) goto fail; @@ -35,7 +35,6 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml) fail: VIR_FREE(actual); - virStoragePoolDefFree(dev); return ret; } diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c index 4c98decc4d..edff8d8477 100644 --- a/tests/storagevolxml2argvtest.c +++ b/tests/storagevolxml2argvtest.c @@ -49,10 +49,10 @@ testCompareXMLToArgvFiles(bool shouldFail, virCommandPtr cmd = NULL; virStoragePoolDefPtr def = NULL; - virStoragePoolDefPtr inputpool = NULL; virStoragePoolObjPtr obj = NULL; VIR_AUTOPTR(virStorageVolDef) vol = NULL; VIR_AUTOPTR(virStorageVolDef) inputvol = NULL; + VIR_AUTOPTR(virStoragePoolDef) inputpool = NULL; if (!(def = virStoragePoolDefParseFile(poolxml))) goto cleanup; @@ -139,7 +139,6 @@ testCompareXMLToArgvFiles(bool shouldFail, ret = 0; cleanup: - virStoragePoolDefFree(inputpool); virCommandFree(cmd); VIR_FREE(actualCmdline); virStoragePoolObjEndAPI(&obj); diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c index 95e205a0ab..cb78bd5b28 100644 --- a/tests/storagevolxml2xmltest.c +++ b/tests/storagevolxml2xmltest.c @@ -19,7 +19,7 @@ testCompareXMLToXMLFiles(const char *poolxml, const char *inxml, { char *actual = NULL; int ret = -1; - virStoragePoolDefPtr pool = NULL; + VIR_AUTOPTR(virStoragePoolDef) pool = NULL; VIR_AUTOPTR(virStorageVolDef) dev = NULL; if (!(pool = virStoragePoolDefParseFile(poolxml))) @@ -38,7 +38,6 @@ testCompareXMLToXMLFiles(const char *poolxml, const char *inxml, fail: VIR_FREE(actual); - virStoragePoolDefFree(pool); return ret; } -- 2.20.1