From nobody Mon Feb 9 02:13:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549651099821169.68919994593637; Fri, 8 Feb 2019 10:38:19 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92FF0C067C2F; Fri, 8 Feb 2019 18:38:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D39760BE0; Fri, 8 Feb 2019 18:38:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CE70918033AF; Fri, 8 Feb 2019 18:38:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x18IbeJW007609 for ; Fri, 8 Feb 2019 13:37:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 686164250; Fri, 8 Feb 2019 18:37:40 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F09960BE0 for ; Fri, 8 Feb 2019 18:37:39 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:06 -0500 Message-Id: <20190208183726.30903-13-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 12/32] storage: Use VIR_AUTOFREE for storage backends X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 08 Feb 2019 18:38:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities. This also allows for the cleanup of some goto paths. Signed-off-by: John Ferlan Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_backend.c | 9 +-- src/storage/storage_backend_disk.c | 62 ++++++----------- src/storage/storage_backend_fs.c | 17 ++--- src/storage/storage_backend_gluster.c | 30 +++----- src/storage/storage_backend_iscsi.c | 73 +++++++------------- src/storage/storage_backend_iscsi_direct.c | 36 ++++------ src/storage/storage_backend_logical.c | 35 +++------- src/storage/storage_backend_mpath.c | 18 ++--- src/storage/storage_backend_rbd.c | 35 +++------- src/storage/storage_backend_scsi.c | 79 ++++++++-------------- src/storage/storage_backend_sheepdog.c | 27 +++----- src/storage/storage_backend_vstorage.c | 25 +++---- src/storage/storage_backend_zfs.c | 15 ++-- src/storage/storage_file_gluster.c | 16 ++--- 14 files changed, 158 insertions(+), 319 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index a54c338cf0..5c8275e978 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -87,8 +87,7 @@ virStorageDriverLoadBackendModule(const char *name, const char *regfunc, bool forceload) { - char *modfile =3D NULL; - int ret; + VIR_AUTOFREE(char *) modfile =3D NULL; =20 if (!(modfile =3D virFileFindResourceFull(name, "libvirt_storage_backend_", @@ -98,11 +97,7 @@ virStorageDriverLoadBackendModule(const char *name, "LIBVIRT_STORAGE_BACKEND_DIR")= )) return -1; =20 - ret =3D virModuleLoad(modfile, regfunc, forceload); - - VIR_FREE(modfile); - - return ret; + return virModuleLoad(modfile, regfunc, forceload); } =20 =20 diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backe= nd_disk.c index 4fb38178b2..4103f2d039 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -56,8 +56,9 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr poo= l, virStorageVolDefPtr vol) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *tmp, *devpath, *partname; + char *tmp, *partname; bool addVol =3D false; + VIR_AUTOFREE(char *) devpath =3D NULL; =20 /* Prepended path will be same for all partitions, so we can * strip the path to form a reasonable pool-unique name @@ -89,7 +90,6 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr poo= l, * way of doing this... */ vol->target.path =3D virStorageBackendStablePath(pool, devpath, tr= ue); - VIR_FREE(devpath); if (vol->target.path =3D=3D NULL) goto error; } @@ -355,12 +355,11 @@ virStorageBackendDiskReadPartitions(virStoragePoolObj= Ptr pool, */ =20 virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *parthelper_path; struct virStorageBackendDiskPoolVolData cbdata =3D { .pool =3D pool, .vol =3D vol, }; - int ret; + VIR_AUTOFREE(char *) parthelper_path =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!(parthelper_path =3D virFileFindResource("libvirt_parthelper", @@ -388,12 +387,7 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjP= tr pool, def->allocation =3D 0; def->capacity =3D def->available =3D 0; =20 - ret =3D virCommandRunNul(cmd, - 6, - virStorageBackendDiskMakeVol, - &cbdata); - VIR_FREE(parthelper_path); - return ret; + return virCommandRunNul(cmd, 6, virStorageBackendDiskMakeVol, &cbdata); } =20 static int @@ -419,8 +413,7 @@ static int virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *parthelper_path; - int ret; + VIR_AUTOFREE(char *) parthelper_path =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (!(parthelper_path =3D virFileFindResource("libvirt_parthelper", @@ -433,12 +426,8 @@ virStorageBackendDiskReadGeometry(virStoragePoolObjPtr= pool) "-g", NULL); =20 - ret =3D virCommandRunNul(cmd, - 3, - virStorageBackendDiskMakePoolGeometry, - pool); - VIR_FREE(parthelper_path); - return ret; + return virCommandRunNul(cmd, 3, virStorageBackendDiskMakePoolGeometry, + pool); } =20 static int @@ -769,13 +758,12 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr p= ool, unsigned int flags) { char *part_num =3D NULL; - char *devpath =3D NULL; char *dev_name; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); char *src_path =3D def->source.devices[0].path; char *srcname =3D last_component(src_path); bool isDevMapperDevice; - int rc =3D -1; + VIR_AUTOFREE(char *) devpath =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 virCheckFlags(0, -1); @@ -799,7 +787,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr poo= l, virReportSystemError(errno, _("Couldn't read volume target path '%s'"= ), vol->target.path); - goto cleanup; + return -1; } dev_name =3D last_component(devpath); } @@ -810,7 +798,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr poo= l, virReportError(VIR_ERR_INTERNAL_ERROR, _("Volume path '%s' did not start with parent " "pool source device name."), dev_name); - goto cleanup; + return -1; } =20 part_num =3D dev_name + strlen(srcname); @@ -824,7 +812,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr poo= l, virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse partition number from target " "'%s'"), dev_name); - goto cleanup; + return -1; } =20 /* eg parted /dev/sda rm 2 or /dev/mapper/mpathc rm 2 */ @@ -835,7 +823,7 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr poo= l, part_num, NULL); if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 /* Refreshing the pool is the easiest option as LOGICAL and EXTENDED * partition allocation/capacity management is handled within @@ -844,12 +832,9 @@ virStorageBackendDiskDeleteVol(virStoragePoolObjPtr po= ol, */ virStoragePoolObjClearVols(pool); if (virStorageBackendDiskRefreshPool(pool) < 0) - goto cleanup; + return -1; =20 - rc =3D 0; - cleanup: - VIR_FREE(devpath); - return rc; + return 0; } =20 =20 @@ -857,11 +842,10 @@ static int virStorageBackendDiskCreateVol(virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { - int res =3D -1; - char *partFormat =3D NULL; unsigned long long startOffset =3D 0, endOffset =3D 0; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virErrorPtr save_err; + VIR_AUTOFREE(char *)partFormat =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(PARTED, @@ -874,11 +858,11 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr p= ool, vol->target.encryption->format !=3D VIR_STORAGE_ENCRYPTION_FORMAT_= LUKS) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("storage pool only supports LUKS encrypted volume= s")); - goto cleanup; + return -1; } =20 if (virStorageBackendDiskPartFormat(pool, vol, &partFormat) !=3D 0) - goto cleanup; + return -1; virCommandAddArg(cmd, partFormat); =20 /* If we're going to encrypt using LUKS, then we could need up to @@ -888,13 +872,13 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr p= ool, =20 if (virStorageBackendDiskPartBoundaries(pool, &startOffset, &endOffset, vol->target.capacity) < 0) - goto cleanup; + return -1; =20 virCommandAddArgFormat(cmd, "%lluB", startOffset); virCommandAddArgFormat(cmd, "%lluB", endOffset); =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 /* wait for device node to show up */ virWaitForDevices(); @@ -918,11 +902,7 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr po= ol, goto error; } =20 - res =3D 0; - - cleanup: - VIR_FREE(partFormat); - return res; + return 0; =20 error: /* Best effort to remove the partition. Ignore any errors @@ -932,7 +912,7 @@ virStorageBackendDiskCreateVol(virStoragePoolObjPtr poo= l, ignore_value(virStorageBackendDiskDeleteVol(pool, vol, 0)); virSetError(save_err); virFreeError(save_err); - goto cleanup; + return -1; } =20 =20 diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend= _fs.c index 0436c25af0..97148acebe 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -246,11 +246,11 @@ virStorageBackendFileSystemIsMounted(virStoragePoolOb= jPtr pool) { int ret =3D -1; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *src =3D NULL; FILE *mtab; struct mntent ent; char buf[1024]; int rc1, rc2; + VIR_AUTOFREE(char *) src =3D NULL; =20 if ((mtab =3D fopen(_PATH_MOUNTED, "r")) =3D=3D NULL) { virReportSystemError(errno, @@ -282,7 +282,6 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjP= tr pool) =20 cleanup: VIR_FORCE_FCLOSE(mtab); - VIR_FREE(src); return ret; } =20 @@ -299,9 +298,8 @@ static int virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *src =3D NULL; - int ret =3D -1; int rc; + VIR_AUTOFREE(char *) src =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (virStorageBackendFileSystemIsValid(pool) < 0) @@ -320,13 +318,7 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr = pool) return -1; =20 cmd =3D virStorageBackendFileSystemMountCmd(MOUNT, def, src); - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - VIR_FREE(src); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 @@ -579,10 +571,10 @@ virStoragePoolDefFSNamespaceParse(xmlXPathContextPtr = ctxt, void **data) { virStoragePoolFSMountOptionsDefPtr cmdopts =3D NULL; - xmlNodePtr *nodes =3D NULL; int nnodes; size_t i; int ret =3D -1; + VIR_AUTOFREE(xmlNodePtr *)nodes =3D NULL; =20 if (xmlXPathRegisterNs(ctxt, BAD_CAST "fs", BAD_CAST STORAGE_POOL_FS_NAMESPACE_HREF) < 0) { @@ -617,7 +609,6 @@ virStoragePoolDefFSNamespaceParse(xmlXPathContextPtr ct= xt, ret =3D 0; =20 cleanup: - VIR_FREE(nodes); virStoragePoolDefFSNamespaceFree(cmdopts); return ret; } diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_gluster.c index 5428bb92ba..1888314d95 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -127,11 +127,9 @@ virStorageBackendGlusterOpen(virStoragePoolObjPtr pool) if (glfs_set_volfile_server(ret->vol, "tcp", ret->uri->server, ret->uri->port) < 0 || glfs_init(ret->vol) < 0) { - char *uri =3D virURIFormat(ret->uri); - - virReportSystemError(errno, _("failed to connect to %s"), - NULLSTR(uri)); - VIR_FREE(uri); + VIR_AUTOFREE(char *) uri =3D NULL; + uri =3D virURIFormat(ret->uri); + virReportSystemError(errno, _("failed to connect to %s"), NULLSTR(= uri)); goto error; } =20 @@ -187,9 +185,8 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGl= usterStatePtr state, virStorageVolDefPtr vol, const char *name) { - int ret =3D -1; - char *path =3D NULL; char *tmp; + VIR_AUTOFREE(char *) path =3D NULL; =20 VIR_FREE(vol->key); VIR_FREE(vol->target.path); @@ -200,35 +197,31 @@ virStorageBackendGlusterSetMetadata(virStorageBackend= GlusterStatePtr state, if (name) { VIR_FREE(vol->name); if (VIR_STRDUP(vol->name, name) < 0) - goto cleanup; + return -1; } =20 if (virAsprintf(&path, "%s%s%s", state->volname, state->dir, vol->name) < 0) - goto cleanup; + return -1; =20 tmp =3D state->uri->path; if (virAsprintf(&state->uri->path, "/%s", path) < 0) { state->uri->path =3D tmp; - goto cleanup; + return -1; } if (!(vol->target.path =3D virURIFormat(state->uri))) { VIR_FREE(state->uri->path); state->uri->path =3D tmp; - goto cleanup; + return -1; } VIR_FREE(state->uri->path); state->uri->path =3D tmp; =20 /* the path is unique enough to serve as a volume key */ if (VIR_STRDUP(vol->key, vol->target.path) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(path); - return ret; + return 0; } =20 =20 @@ -244,10 +237,10 @@ virStorageBackendGlusterRefreshVol(virStorageBackendG= lusterStatePtr state, int ret =3D -1; glfs_fd_t *fd =3D NULL; virStorageSourcePtr meta =3D NULL; - char *header =3D NULL; ssize_t len; int backingFormat; VIR_AUTOPTR(virStorageVolDef) vol =3D NULL; + VIR_AUTOFREE(char *) header =3D NULL; =20 *volptr =3D NULL; =20 @@ -333,7 +326,6 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlu= sterStatePtr state, virStorageSourceFree(meta); if (fd) glfs_close(fd); - VIR_FREE(header); return ret; } =20 diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_back= end_iscsi.c index dc1a983b58..9314427cda 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -130,27 +130,20 @@ static int virStorageBackendISCSIFindLUs(virStoragePoolObjPtr pool, const char *session) { - char *sysfs_path; - int retval =3D -1; uint32_t host; + VIR_AUTOFREE(char *) sysfs_path =3D NULL; =20 if (virAsprintf(&sysfs_path, "/sys/class/iscsi_session/session%s/device", session) = < 0) - goto cleanup; + return -1; =20 if (virStorageBackendISCSIGetHostNumber(sysfs_path, &host) < 0) - goto cleanup; + return -1; =20 if (virStorageBackendSCSIFindLUs(pool, host) < 0) - goto cleanup; - - retval =3D 0; - - cleanup: - - VIR_FREE(sysfs_path); + return -1; =20 - return retval; + return 0; } =20 =20 @@ -167,7 +160,7 @@ virStorageBackendISCSIFindPoolSources(const char *srcSp= ec, .nsources =3D 0, .sources =3D NULL }; - char *portal =3D NULL; + VIR_AUTOFREE(char *) portal =3D NULL; VIR_AUTOPTR(virStoragePoolSource) source =3D NULL; =20 virCheckFlags(0, NULL); @@ -223,10 +216,10 @@ virStorageBackendISCSIFindPoolSources(const char *src= Spec, } VIR_FREE(list.sources); } + /* NB: Not virString -like, managed by VIR_APPEND_ELEMENT */ for (i =3D 0; i < ntargets; i++) VIR_FREE(targets[i]); VIR_FREE(targets); - VIR_FREE(portal); return ret; } =20 @@ -235,8 +228,8 @@ virStorageBackendISCSICheckPool(virStoragePoolObjPtr po= ol, bool *isActive) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *session =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) session =3D NULL; =20 *isActive =3D false; =20 @@ -259,10 +252,8 @@ virStorageBackendISCSICheckPool(virStoragePoolObjPtr p= ool, return -1; } =20 - if ((session =3D virStorageBackendISCSISession(pool, true)) !=3D NULL)= { + if ((session =3D virStorageBackendISCSISession(pool, true))) *isActive =3D true; - VIR_FREE(session); - } ret =3D 0; =20 return ret; @@ -330,9 +321,8 @@ static int virStorageBackendISCSIStartPool(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *portal =3D NULL; - char *session =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) portal =3D NULL; + VIR_AUTOFREE(char *) session =3D NULL; =20 if (def->source.nhost !=3D 1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -355,50 +345,40 @@ virStorageBackendISCSIStartPool(virStoragePoolObjPtr = pool) =20 if ((session =3D virStorageBackendISCSISession(pool, true)) =3D=3D NUL= L) { if ((portal =3D virStorageBackendISCSIPortal(&def->source)) =3D=3D= NULL) - goto cleanup; + return -1; =20 /* Create a static node record for the IQN target. Must be done * in order for login to the target */ if (virISCSINodeNew(portal, def->source.devices[0].path) < 0) - goto cleanup; + return -1; =20 if (virStorageBackendISCSISetAuth(portal, &def->source) < 0) - goto cleanup; + return -1; =20 if (virISCSIConnectionLogin(portal, def->source.initiator.iqn, def->source.devices[0].path) < 0) - goto cleanup; + return -1; } - ret =3D 0; - - cleanup: - VIR_FREE(portal); - VIR_FREE(session); - return ret; + return 0; } =20 static int virStorageBackendISCSIRefreshPool(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *session =3D NULL; + VIR_AUTOFREE(char *) session =3D NULL; =20 def->allocation =3D def->capacity =3D def->available =3D 0; =20 if ((session =3D virStorageBackendISCSISession(pool, false)) =3D=3D NU= LL) - goto cleanup; + return -1; if (virISCSIRescanLUNs(session) < 0) - goto cleanup; + return -1; if (virStorageBackendISCSIFindLUs(pool, session) < 0) - goto cleanup; - VIR_FREE(session); + return -1; =20 return 0; - - cleanup: - VIR_FREE(session); - return -1; } =20 =20 @@ -406,13 +386,11 @@ static int virStorageBackendISCSIStopPool(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *portal; - char *session; - int ret =3D -1; + VIR_AUTOFREE(char *) portal =3D NULL; + VIR_AUTOFREE(char *) session =3D NULL; =20 if ((session =3D virStorageBackendISCSISession(pool, true)) =3D=3D NUL= L) return 0; - VIR_FREE(session); =20 if ((portal =3D virStorageBackendISCSIPortal(&def->source)) =3D=3D NUL= L) return -1; @@ -420,12 +398,9 @@ virStorageBackendISCSIStopPool(virStoragePoolObjPtr po= ol) if (virISCSIConnectionLogout(portal, def->source.initiator.iqn, def->source.devices[0].path) < 0) - goto cleanup; - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(portal); - return ret; + return 0; } =20 virStorageBackend virStorageBackendISCSI =3D { diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index cf48c29cde..464732f7ab 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -421,15 +421,13 @@ virISCSIDirectUpdateTargets(struct iscsi_context *isc= si, } =20 for (tmp_addr =3D addr; tmp_addr; tmp_addr =3D tmp_addr->next) { - char *target =3D NULL; + VIR_AUTOFREE(char *) target =3D NULL; =20 if (VIR_STRDUP(target, tmp_addr->target_name) < 0) goto cleanup; =20 - if (VIR_APPEND_ELEMENT(tmp_targets, tmp_ntargets, target) < 0) { - VIR_FREE(target); + if (VIR_APPEND_ELEMENT(tmp_targets, tmp_ntargets, target) < 0) goto cleanup; - } } =20 VIR_STEAL_PTR(*targets, tmp_targets); @@ -489,7 +487,7 @@ virStorageBackendISCSIDirectFindPoolSources(const char = *srcSpec, .nsources =3D 0, .sources =3D NULL }; - char *portal =3D NULL; + VIR_AUTOFREE(char *) portal =3D NULL; VIR_AUTOPTR(virStoragePoolSource) source =3D NULL; =20 virCheckFlags(0, NULL); @@ -550,7 +548,6 @@ virStorageBackendISCSIDirectFindPoolSources(const char = *srcSpec, for (i =3D 0; i < ntargets; i++) VIR_FREE(targets[i]); VIR_FREE(targets); - VIR_FREE(portal); return ret; } =20 @@ -560,7 +557,7 @@ virStorageBackendISCSIDirectSetConnection(virStoragePoo= lObjPtr pool, { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); struct iscsi_context *iscsi =3D NULL; - char *portal =3D NULL; + VIR_AUTOFREE(char *) portal =3D NULL; =20 if (!(iscsi =3D virISCSIDirectCreateContext(def->source.initiator.iqn)= )) goto error; @@ -577,7 +574,6 @@ virStorageBackendISCSIDirectSetConnection(virStoragePoo= lObjPtr pool, VIR_STEAL_PTR(*portalRet, portal); =20 cleanup: - VIR_FREE(portal); return iscsi; =20 error: @@ -590,19 +586,14 @@ static int virStorageBackendISCSIDirectRefreshPool(virStoragePoolObjPtr pool) { struct iscsi_context *iscsi =3D NULL; - char *portal =3D NULL; int ret =3D -1; - if (!(iscsi =3D virStorageBackendISCSIDirectSetConnection(pool, &porta= l))) - goto cleanup; - if (virISCSIDirectReportLuns(pool, iscsi, portal) < 0) - goto disconect; + VIR_AUTOFREE(char *) portal =3D NULL; =20 - ret =3D 0; - disconect: + if (!(iscsi =3D virStorageBackendISCSIDirectSetConnection(pool, &porta= l))) + return -1; + ret =3D virISCSIDirectReportLuns(pool, iscsi, portal); virISCSIDirectDisconnect(iscsi); iscsi_destroy_context(iscsi); - cleanup: - VIR_FREE(portal); return ret; } =20 @@ -638,7 +629,7 @@ virStorageBackendISCSIDirectVolWipeZero(virStorageVolDe= fPtr vol, struct scsi_task *task =3D NULL; int lun =3D 0; int ret =3D -1; - unsigned char *data; + VIR_AUTOFREE(unsigned char *) data =3D NULL; =20 if (virStorageBackendISCSIDirectGetLun(vol, &lun) < 0) return ret; @@ -655,22 +646,19 @@ virStorageBackendISCSIDirectVolWipeZero(virStorageVol= DefPtr vol, if (!(task =3D iscsi_write10_sync(iscsi, lun, lba, data, block_size * BLOCK_PER_PACKET, block_size, 0, 0, 0, 0, 0))) - goto cleanup; + return -1; scsi_free_scsi_task(task); lba +=3D BLOCK_PER_PACKET; } else { if (!(task =3D iscsi_write10_sync(iscsi, lun, lba, data, block= _size, block_size, 0, 0, 0, 0, 0))) - goto cleanup; + return -1; scsi_free_scsi_task(task); lba++; } } =20 - ret =3D 0; - cleanup: - VIR_FREE(data); - return ret; + return 0; } =20 static int diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index 9ebc560a46..c61d03519f 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -117,14 +117,14 @@ virStorageBackendLogicalParseVolExtents(virStorageVol= DefPtr vol, { int nextents, ret =3D -1; const char *regex_unit =3D "(\\S+)\\((\\S+)\\)"; - char *regex =3D NULL; - regex_t *reg =3D NULL; - regmatch_t *vars =3D NULL; char *p =3D NULL; size_t i; int err, nvars; unsigned long long offset, size, length; virStorageVolSourceExtent extent; + VIR_AUTOFREE(char *) regex =3D NULL; + VIR_AUTOFREE(regex_t *) reg =3D NULL; + VIR_AUTOFREE(regmatch_t *) vars =3D NULL; =20 memset(&extent, 0, sizeof(extent)); =20 @@ -202,7 +202,7 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDe= fPtr vol, for (i =3D 0; i < nextents; i++) { size_t j; int len; - char *offset_str =3D NULL; + VIR_AUTOFREE(char *) offset_str =3D NULL; =20 j =3D (i * 2) + 1; len =3D vars[j].rm_eo - vars[j].rm_so; @@ -219,10 +219,8 @@ virStorageBackendLogicalParseVolExtents(virStorageVolD= efPtr vol, if (virStrToLong_ull(offset_str, NULL, 10, &offset) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed volume extent offset value")); - VIR_FREE(offset_str); goto cleanup; } - VIR_FREE(offset_str); extent.start =3D offset * size; extent.end =3D (offset * size) + length; =20 @@ -234,9 +232,6 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDe= fPtr vol, ret =3D 0; =20 cleanup: - VIR_FREE(regex); - VIR_FREE(reg); - VIR_FREE(vars); VIR_FREE(extent.path); return ret; } @@ -459,15 +454,15 @@ virStorageBackendLogicalFindPoolSourcesFunc(char **co= nst groups, void *data) { virStoragePoolSourceListPtr sourceList =3D data; - char *pvname =3D NULL; - char *vgname =3D NULL; size_t i; virStoragePoolSourceDevicePtr dev; virStoragePoolSource *thisSource; + VIR_AUTOFREE(char *) pvname =3D NULL; + VIR_AUTOFREE(char *) vgname =3D NULL; =20 if (VIR_STRDUP(pvname, groups[0]) < 0 || VIR_STRDUP(vgname, groups[1]) < 0) - goto error; + return -1; =20 thisSource =3D NULL; for (i =3D 0; i < sourceList->nsources; i++) { @@ -479,30 +474,22 @@ virStorageBackendLogicalFindPoolSourcesFunc(char **co= nst groups, =20 if (thisSource =3D=3D NULL) { if (!(thisSource =3D virStoragePoolSourceListNewSource(sourceList)= )) - goto error; + return -1; =20 - thisSource->name =3D vgname; + VIR_STEAL_PTR(thisSource->name, vgname); } - else - VIR_FREE(vgname); =20 if (VIR_REALLOC_N(thisSource->devices, thisSource->ndevice + 1) !=3D 0) - goto error; + return -1; =20 dev =3D &thisSource->devices[thisSource->ndevice]; thisSource->ndevice++; thisSource->format =3D VIR_STORAGE_POOL_LOGICAL_LVM2; =20 memset(dev, 0, sizeof(*dev)); - dev->path =3D pvname; + VIR_STEAL_PTR(dev->path, pvname); =20 return 0; - - error: - VIR_FREE(pvname); - VIR_FREE(vgname); - - return -1; } =20 /* diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_back= end_mpath.c index 423f945fbc..b78eb726b2 100644 --- a/src/storage/storage_backend_mpath.c +++ b/src/storage/storage_backend_mpath.c @@ -153,33 +153,32 @@ static int virStorageBackendCreateVols(virStoragePoolObjPtr pool, struct dm_names *names) { - int retval =3D -1, is_mpath =3D 0; - char *map_device =3D NULL; + int is_mpath =3D 0; uint32_t minor =3D -1; uint32_t next; + VIR_AUTOFREE(char *) map_device =3D NULL; =20 do { is_mpath =3D virStorageBackendIsMultipath(names->name); =20 if (is_mpath < 0) - goto out; + return -1; =20 if (is_mpath =3D=3D 1) { =20 if (virAsprintf(&map_device, "mapper/%s", names->name) < 0) - goto out; + return -1; =20 if (virStorageBackendGetMinorNumber(names->name, &minor) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to get %s minor number"), names->name); - goto out; + return -1; } =20 if (virStorageBackendMpathNewVol(pool, minor, map_device) < 0) - goto out; + return -1; =20 - VIR_FREE(map_device); } =20 /* Given the way libdevmapper returns its data, I don't see @@ -191,10 +190,7 @@ virStorageBackendCreateVols(virStoragePoolObjPtr pool, =20 } while (next); =20 - retval =3D 0; - out: - VIR_FREE(map_device); - return retval; + return 0; } =20 =20 diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backen= d_rbd.c index ece04f0f2d..2b7af1db23 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -86,10 +86,10 @@ virStoragePoolDefRBDNamespaceParse(xmlXPathContextPtr c= txt, void **data) { virStoragePoolRBDConfigOptionsDefPtr cmdopts =3D NULL; - xmlNodePtr *nodes =3D NULL; int nnodes; size_t i; int ret =3D -1; + VIR_AUTOFREE(xmlNodePtr *)nodes =3D NULL; =20 if (xmlXPathRegisterNs(ctxt, BAD_CAST "rbd", BAD_CAST STORAGE_POOL_RBD_NAMESPACE_HREF) < 0) { @@ -145,7 +145,6 @@ virStoragePoolDefRBDNamespaceParse(xmlXPathContextPtr c= txt, ret =3D 0; =20 cleanup: - VIR_FREE(nodes); virStoragePoolDefRBDNamespaceFree(cmdopts); return ret; } @@ -213,12 +212,12 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRB= DStatePtr ptr, char *rados_key =3D NULL; virBuffer mon_host =3D VIR_BUFFER_INITIALIZER; size_t i; - char *mon_buff =3D NULL; const char *client_mount_timeout =3D "30"; const char *mon_op_timeout =3D "30"; const char *osd_op_timeout =3D "30"; const char *rbd_default_format =3D "2"; virConnectPtr conn =3D NULL; + VIR_AUTOFREE(char *) mon_buff =3D NULL; =20 if (authdef) { VIR_DEBUG("Using cephx authorization, username: %s", authdef->user= name); @@ -348,7 +347,6 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDS= tatePtr ptr, =20 virObjectUnref(conn); virBufferFreeAndReset(&mon_host); - VIR_FREE(mon_buff); return ret; } =20 @@ -574,11 +572,12 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr = pool) int ret =3D -1; int len =3D -1; int r =3D 0; - char *name, *names =3D NULL; + char *name; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virStorageBackendRBDStatePtr ptr =3D NULL; struct rados_cluster_stat_t clusterstat; struct rados_pool_stat_t poolstat; + VIR_AUTOFREE(char *) names =3D NULL; =20 if (!(ptr =3D virStorageBackendRBDNewState(pool))) goto cleanup; @@ -662,7 +661,6 @@ virStorageBackendRBDRefreshPool(virStoragePoolObjPtr po= ol) ret =3D 0; =20 cleanup: - VIR_FREE(names); virStorageBackendRBDFreeState(&ptr); return ret; } @@ -677,8 +675,8 @@ virStorageBackendRBDCleanupSnapshots(rados_ioctx_t ioct= x, int max_snaps =3D 128; int snap_count, protected; size_t i; - rbd_snap_info_t *snaps =3D NULL; rbd_image_t image =3D NULL; + VIR_AUTOFREE(rbd_snap_info_t *) snaps =3D NULL; =20 if ((r =3D rbd_open(ioctx, vol->name, &image, NULL)) < 0) { virReportSystemError(-r, _("failed to open the RBD image '%s'"), @@ -737,8 +735,6 @@ virStorageBackendRBDCleanupSnapshots(rados_ioctx_t ioct= x, if (snaps) rbd_snap_list_end(snaps); =20 - VIR_FREE(snaps); - if (image) rbd_close(image); =20 @@ -949,8 +945,8 @@ virStorageBackendRBDSnapshotFindNoDiff(rbd_image_t imag= e, int max_snaps =3D 128; size_t i; int diff; - rbd_snap_info_t *snaps =3D NULL; rbd_image_info_t info; + VIR_AUTOFREE(rbd_snap_info_t *) snaps =3D NULL; =20 if ((r =3D rbd_stat(image, &info, sizeof(info))) < 0) { virReportSystemError(-r, _("failed to stat the RBD image %s"), @@ -1023,8 +1019,6 @@ virStorageBackendRBDSnapshotFindNoDiff(rbd_image_t im= age, if (snaps) rbd_snap_list_end(snaps); =20 - VIR_FREE(snaps); - return ret; } =20 @@ -1098,8 +1092,8 @@ virStorageBackendRBDCloneImage(rados_ioctx_t io, uint64_t stripe_count; uint64_t stripe_unit; virBuffer snapname =3D VIR_BUFFER_INITIALIZER; - char *snapname_buff =3D NULL; rbd_image_t image =3D NULL; + VIR_AUTOFREE(char *) snapname_buff =3D NULL; =20 if ((r =3D rbd_open(io, origvol, &image, NULL)) < 0) { virReportSystemError(-r, _("failed to open the RBD image %s"), @@ -1170,7 +1164,6 @@ virStorageBackendRBDCloneImage(rados_ioctx_t io, =20 cleanup: virBufferFreeAndReset(&snapname); - VIR_FREE(snapname_buff); =20 if (image) rbd_close(image); @@ -1271,13 +1264,12 @@ virStorageBackendRBDVolWipeZero(rbd_image_t image, uint64_t stripe_count) { int r =3D -1; - int ret =3D -1; unsigned long long offset =3D 0; unsigned long long length; - char *writebuf; + VIR_AUTOFREE(char *) writebuf =3D NULL; =20 if (VIR_ALLOC_N(writebuf, info->obj_size * stripe_count) < 0) - goto cleanup; + return -1; =20 while (offset < info->size) { length =3D MIN((info->size - offset), (info->obj_size * stripe_cou= nt)); @@ -1286,7 +1278,7 @@ virStorageBackendRBDVolWipeZero(rbd_image_t image, virReportSystemError(-r, _("writing %llu bytes failed on " "RBD image %s at offset %llu"), length, imgname, offset); - goto cleanup; + return -1; } =20 VIR_DEBUG("Wrote %llu bytes to RBD image %s at offset %llu", @@ -1295,12 +1287,7 @@ virStorageBackendRBDVolWipeZero(rbd_image_t image, offset +=3D length; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(writebuf); - - return ret; + return 0; } =20 static int diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backe= nd_scsi.c index 14f01f9ec0..7460349c81 100644 --- a/src/storage/storage_backend_scsi.c +++ b/src/storage/storage_backend_scsi.c @@ -56,16 +56,14 @@ static int virStorageBackendSCSITriggerRescan(uint32_t host) { int fd =3D -1; - int retval =3D 0; - char *path; + int retval =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; =20 VIR_DEBUG("Triggering rescan of host %d", host); =20 if (virAsprintf(&path, "%s/host%u/scan", - LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0) { - retval =3D -1; - goto out; - } + LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0) + return -1; =20 VIR_DEBUG("Scan trigger path is '%s'", path); =20 @@ -75,8 +73,7 @@ virStorageBackendSCSITriggerRescan(uint32_t host) virReportSystemError(errno, _("Could not open '%s' to trigger host scan"), path); - retval =3D -1; - goto free_path; + goto cleanup; } =20 if (safewrite(fd, @@ -86,13 +83,12 @@ virStorageBackendSCSITriggerRescan(uint32_t host) virReportSystemError(errno, _("Write to '%s' to trigger host scan failed"= ), path); - retval =3D -1; } =20 + retval =3D 0; + + cleanup: VIR_FORCE_CLOSE(fd); - free_path: - VIR_FREE(path); - out: VIR_DEBUG("Rescan of host %d complete", host); return retval; } @@ -178,7 +174,6 @@ static char * getAdapterName(virStorageAdapterPtr adapter) { char *name =3D NULL; - char *parentaddr =3D NULL; =20 if (adapter->type =3D=3D VIR_STORAGE_ADAPTER_TYPE_SCSI_HOST) { virStorageAdapterSCSIHostPtr scsi_host =3D &adapter->data.scsi_hos= t; @@ -192,7 +187,7 @@ getAdapterName(virStorageAdapterPtr adapter) addr->slot, addr->function, unique_id))) - goto cleanup; + return NULL; } else { ignore_value(VIR_STRDUP(name, scsi_host->name)); } @@ -206,8 +201,6 @@ getAdapterName(virStorageAdapterPtr adapter) } } =20 - cleanup: - VIR_FREE(parentaddr); return name; } =20 @@ -248,10 +241,10 @@ checkParent(const char *name, const char *parent_name) { unsigned int host_num; - char *scsi_host_name =3D NULL; - char *vhba_parent =3D NULL; bool retval =3D false; virConnectPtr conn =3D NULL; + VIR_AUTOFREE(char *) scsi_host_name =3D NULL; + VIR_AUTOFREE(char *) vhba_parent =3D NULL; =20 VIR_DEBUG("name=3D%s, parent_name=3D%s", name, parent_name); =20 @@ -291,8 +284,6 @@ checkParent(const char *name, =20 cleanup: virObjectUnref(conn); - VIR_FREE(vhba_parent); - VIR_FREE(scsi_host_name); return retval; } =20 @@ -302,10 +293,9 @@ createVport(virStoragePoolDefPtr def, const char *configFile, virStorageAdapterFCHostPtr fchost) { - char *name =3D NULL; virStoragePoolFCRefreshInfoPtr cbdata =3D NULL; virThread thread; - int ret =3D -1; + VIR_AUTOFREE(char *) name =3D NULL; =20 VIR_DEBUG("configFile=3D'%s' parent=3D'%s', wwnn=3D'%s' wwpn=3D'%s'", NULLSTR(configFile), NULLSTR(fchost->parent), @@ -317,14 +307,14 @@ createVport(virStoragePoolDefPtr def, */ if ((name =3D virVHBAGetHostByWWN(NULL, fchost->wwnn, fchost->wwpn))) { if (!(checkName(name))) - goto cleanup; + return -1; =20 /* If a parent was provided, let's make sure the 'name' we've * retrieved has the same parent. If not this will cause failure. = */ if (!fchost->parent || checkParent(name, fchost->parent)) - ret =3D 0; + return 0; =20 - goto cleanup; + return -1; } =20 /* Since we're creating the vHBA, then we need to manage removing it @@ -336,12 +326,12 @@ createVport(virStoragePoolDefPtr def, fchost->managed =3D VIR_TRISTATE_BOOL_YES; if (configFile) { if (virStoragePoolSaveConfig(configFile, def) < 0) - goto cleanup; + return -1; } } =20 if (!(name =3D virNodeDeviceCreateVport(fchost))) - goto cleanup; + return -1; =20 /* Creating our own VPORT didn't leave enough time to find any LUN's, * so, let's create a thread whose job it is to call the FindLU's with @@ -360,11 +350,7 @@ createVport(virStoragePoolDefPtr def, } } =20 - ret =3D 0; - - cleanup: - VIR_FREE(name); - return ret; + return 0; } =20 =20 @@ -373,10 +359,9 @@ virStorageBackendSCSICheckPool(virStoragePoolObjPtr po= ol, bool *isActive) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *path =3D NULL; - char *name =3D NULL; unsigned int host; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) name =3D NULL; =20 *isActive =3D false; =20 @@ -394,28 +379,23 @@ virStorageBackendSCSICheckPool(virStoragePoolObjPtr p= ool, } =20 if (virSCSIHostGetNumber(name, &host) < 0) - goto cleanup; + return -1; =20 if (virAsprintf(&path, "%s/host%d", LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0) - goto cleanup; + return -1; =20 *isActive =3D virFileExists(path); =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(name); - return ret; + return 0; } =20 static int virStorageBackendSCSIRefreshPool(virStoragePoolObjPtr pool) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *name =3D NULL; unsigned int host; - int ret =3D -1; + VIR_AUTOFREE(char *) name =3D NULL; =20 def->allocation =3D def->capacity =3D def->available =3D 0; =20 @@ -423,20 +403,17 @@ virStorageBackendSCSIRefreshPool(virStoragePoolObjPtr= pool) return -1; =20 if (virSCSIHostGetNumber(name, &host) < 0) - goto out; + return -1; =20 VIR_DEBUG("Scanning host%u", host); =20 if (virStorageBackendSCSITriggerRescan(host) < 0) - goto out; + return -1; =20 if (virStorageBackendSCSIFindLUs(pool, host) < 0) - goto out; + return -1; =20 - ret =3D 0; - out: - VIR_FREE(name); - return ret; + return 0; } =20 =20 diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_b= ackend_sheepdog.c index 73dcfb2f40..d3f126da8d 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -136,9 +136,8 @@ virStorageBackendSheepdogAddVolume(virStoragePoolObjPtr= pool, const char *diskIn static int virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr pool) { - int ret =3D -1; - char *output =3D NULL; size_t i; + VIR_AUTOFREE(char *) output =3D NULL; VIR_AUTOPTR(virString) lines =3D NULL; VIR_AUTOPTR(virString) cells =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; @@ -147,11 +146,11 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePool= ObjPtr pool) virStorageBackendSheepdogAddHostArg(cmd, pool); virCommandSetOutputBuffer(cmd, &output); if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 lines =3D virStringSplit(output, "\n", 0); if (lines =3D=3D NULL) - goto cleanup; + return -1; =20 for (i =3D 0; lines[i]; i++) { const char *line =3D lines[i]; @@ -163,42 +162,34 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePool= ObjPtr pool) if (cells !=3D NULL && virStringListLength((const char * const *)cells) > 2) { if (virStorageBackendSheepdogAddVolume(pool, cells[1]) < 0) - goto cleanup; + return -1; } =20 virStringListFree(cells); cells =3D NULL; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(output); - return ret; + return 0; } =20 =20 static int virStorageBackendSheepdogRefreshPool(virStoragePoolObjPtr pool) { - int ret =3D -1; - char *output =3D NULL; + VIR_AUTOFREE(char *) output =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(SHEEPDOGCLI, "node", "info", "-r", NULL); virStorageBackendSheepdogAddHostArg(cmd, pool); virCommandSetOutputBuffer(cmd, &output); if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 if (virStorageBackendSheepdogParseNodeInfo(virStoragePoolObjGetDef(poo= l), output) < 0) - goto cleanup; + return -1; =20 - ret =3D virStorageBackendSheepdogRefreshAllVol(pool); - cleanup: - VIR_FREE(output); - return ret; + return virStorageBackendSheepdogRefreshAllVol(pool); } =20 =20 diff --git a/src/storage/storage_backend_vstorage.c b/src/storage/storage_b= ackend_vstorage.c index 8c5becd4c4..df157a48b1 100644 --- a/src/storage/storage_backend_vstorage.c +++ b/src/storage/storage_backend_vstorage.c @@ -39,9 +39,9 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool) { int ret =3D -1; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *grp_name =3D NULL; - char *usr_name =3D NULL; - char *mode =3D NULL; + VIR_AUTOFREE(char *) grp_name =3D NULL; + VIR_AUTOFREE(char *) usr_name =3D NULL; + VIR_AUTOFREE(char *) mode =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /* Check the permissions */ @@ -55,13 +55,13 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool) /* Convert ids to names because vstorage uses names */ =20 if (!(grp_name =3D virGetGroupName(def->target.perms.gid))) - goto cleanup; + return -1; =20 if (!(usr_name =3D virGetUserName(def->target.perms.uid))) - goto cleanup; + return -1; =20 if (virAsprintf(&mode, "%o", def->target.perms.mode) < 0) - goto cleanup; + return -1; =20 cmd =3D virCommandNewArgList(VSTORAGE_MOUNT, "-c", def->source.name, @@ -70,15 +70,7 @@ virStorageBackendVzPoolStart(virStoragePoolObjPtr pool) "-g", grp_name, "-u", usr_name, NULL); =20 - if (virCommandRun(cmd, NULL) < 0) - goto cleanup; - ret =3D 0; - - cleanup: - VIR_FREE(mode); - VIR_FREE(grp_name); - VIR_FREE(usr_name); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 @@ -90,7 +82,7 @@ virStorageBackendVzIsMounted(virStoragePoolObjPtr pool) FILE *mtab; struct mntent ent; char buf[1024]; - char *cluster =3D NULL; + VIR_AUTOFREE(char *) cluster =3D NULL; =20 if (virAsprintf(&cluster, "vstorage://%s", def->source.name) < 0) return -1; @@ -115,7 +107,6 @@ virStorageBackendVzIsMounted(virStoragePoolObjPtr pool) =20 cleanup: VIR_FORCE_FCLOSE(mtab); - VIR_FREE(cluster); return ret; } =20 diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backen= d_zfs.c index 7d1a3dd2cd..7ffdff638e 100644 --- a/src/storage/storage_backend_zfs.c +++ b/src/storage/storage_backend_zfs.c @@ -52,7 +52,7 @@ static int virStorageBackendZFSVolModeNeeded(void) { int ret =3D -1, exit_code =3D -1; - char *error =3D NULL; + VIR_AUTOFREE(char *) error =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 /* 'zfs get' without arguments prints out @@ -77,7 +77,6 @@ virStorageBackendZFSVolModeNeeded(void) ret =3D 0; =20 cleanup: - VIR_FREE(error); return ret; } =20 @@ -86,13 +85,12 @@ virStorageBackendZFSCheckPool(virStoragePoolObjPtr pool= ATTRIBUTE_UNUSED, bool *isActive) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *devpath; + VIR_AUTOFREE(char *) devpath =3D NULL; =20 if (virAsprintf(&devpath, "/dev/zvol/%s", def->source.name) < 0) return -1; *isActive =3D virFileIsDir(devpath); - VIR_FREE(devpath); =20 return 0; } @@ -178,10 +176,10 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr poo= l, virStorageVolDefPtr vol) { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - char *volumes_list =3D NULL; size_t i; VIR_AUTOPTR(virString) lines =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; + VIR_AUTOFREE(char *) volumes_list =3D NULL; =20 /** * $ zfs list -Hp -t volume -o name,volsize -r test @@ -203,10 +201,10 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr poo= l, NULL); virCommandSetOutputBuffer(cmd, &volumes_list); if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 if (!(lines =3D virStringSplit(volumes_list, "\n", 0))) - goto cleanup; + return -1; =20 for (i =3D 0; lines[i]; i++) { if (STREQ(lines[i], "")) @@ -216,9 +214,6 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool, continue; } =20 - cleanup: - VIR_FREE(volumes_list); - return 0; } =20 diff --git a/src/storage/storage_file_gluster.c b/src/storage/storage_file_= gluster.c index f8bbde8cfe..7c2189d297 100644 --- a/src/storage/storage_file_gluster.c +++ b/src/storage/storage_file_gluster.c @@ -258,10 +258,10 @@ virStorageFileBackendGlusterReadlinkCallback(const ch= ar *path, void *data) { virStorageFileBackendGlusterPrivPtr priv =3D data; - char *buf =3D NULL; size_t bufsiz =3D 0; ssize_t ret; struct stat st; + VIR_AUTOFREE(char *) buf =3D NULL; =20 *linkpath =3D NULL; =20 @@ -277,13 +277,13 @@ virStorageFileBackendGlusterReadlinkCallback(const ch= ar *path, =20 realloc: if (VIR_EXPAND_N(buf, bufsiz, 256) < 0) - goto error; + return -1; =20 if ((ret =3D glfs_readlink(priv->vol, path, buf, bufsiz)) < 0) { virReportSystemError(errno, _("failed to read link of gluster file '%s'"), path); - goto error; + return -1; } =20 if (ret =3D=3D bufsiz) @@ -291,13 +291,9 @@ virStorageFileBackendGlusterReadlinkCallback(const cha= r *path, =20 buf[ret] =3D '\0'; =20 - *linkpath =3D buf; + VIR_STEAL_PTR(*linkpath, buf); =20 return 0; - - error: - VIR_FREE(buf); - return -1; } =20 =20 @@ -305,7 +301,7 @@ static const char * virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src) { virStorageFileBackendGlusterPrivPtr priv =3D src->drv->priv; - char *filePath =3D NULL; + VIR_AUTOFREE(char *) filePath =3D NULL; =20 if (priv->canonpath) return priv->canonpath; @@ -321,8 +317,6 @@ virStorageFileBackendGlusterGetUniqueIdentifier(virStor= ageSourcePtr src) src->volume, filePath)); =20 - VIR_FREE(filePath); - return priv->canonpath; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list