From nobody Mon Dec 15 01:36:42 2025 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; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152812475848094.251929500232; Mon, 4 Jun 2018 08:05:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0AEE25355E; Mon, 4 Jun 2018 15:05:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F03A81057FA3; Mon, 4 Jun 2018 15:05:54 +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 46DB14CA85; Mon, 4 Jun 2018 15:05:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w54Eb6e6008207 for ; Mon, 4 Jun 2018 10:37:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 90B4F308BDAE; Mon, 4 Jun 2018 14:37:06 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 868F2308BDB0 for ; Mon, 4 Jun 2018 14:37:06 +0000 (UTC) Received: from mail-pg0-f66.google.com (mail-pg0-f66.google.com [74.125.83.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BFCF0B8904 for ; Mon, 4 Jun 2018 14:36:54 +0000 (UTC) Received: by mail-pg0-f66.google.com with SMTP id 15-v6so14210798pge.2 for ; Mon, 04 Jun 2018 07:36:54 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=LROB1BcLvMnLmpxtRKEQzAniJqraawzxcglwny+sj3Q=; b=T8/OuG73sSC57ZwQK292aDOvQjFzRrTl0SJ5fydD0OZMihJc9vN1predTDUj+qgwqb y5mD+8QXi+DBg96rCSLKDI8TyYif28PD+53gVJbQg2MHNMIWjeKOz9ksQAyQk07uNGEp 2t20Devl7L59K7N7XRaR6oLKeWR2p0nexlbzyiP8RuO5kGZqkA4nAts/YE4INwprotKm 0LsQEArV4YkfCat00RuQ3ic6w36EOj1vcmGN+BFO+LAoUpLZ0m/0uAPFc1tf1asr9/Dl QRnZwngwLa0sNbRjdP96jz3uHJPcen88Gg1TIgE9OuXqcLi2Li9ie6shrPxNXaVPpjhG HmwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=LROB1BcLvMnLmpxtRKEQzAniJqraawzxcglwny+sj3Q=; b=M3tOo9UlAcFayMWgQ0Rv2X5oB01tOhQ+r8oRgirVwtOibLy4p5kcshPYhLek8mknVJ kTD38u87Z6dRFEVEdtKcy27od2hYDhqRNSG3gzY0HXPtYRgLdQZBDHXHv5dg6mvXElRk 70wNGwH/yXH8rud8leqqqck+pytm2fFCTpfmU/rWqAzYPHcHvloSGiSjpjvp6ZXpUkgw I6jgvkWr9mdTQoTwcBJNPtCbV2cOz7yokkeO2/i7G0itYMwrjrdYlaE0WhMsjIBzAg2u Sv+uij6l6fYDdIt05GQUcaQYylhAMxtfxsWsd8FteHva8NTkqJrAi5lBlWF6VaBEQogL G58Q== X-Gm-Message-State: ALKqPwcfEF1w51liNzS1cfMVLjbl+DrSz77ap+SCcKkh83xRSzavzVbm 7S06uGWEd0IHuAi6WF6N5dNu2UgK X-Google-Smtp-Source: ADUXVKJykbAzr1srPb4Xmw++TGmMv5tsTCn0PzRCFe2Olsn9XpczjZnDuN1W1iMp67PJkJ3YJeULuw== X-Received: by 2002:a65:4204:: with SMTP id c4-v6mr17125914pgq.26.1528123013773; Mon, 04 Jun 2018 07:36:53 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:12 +0530 Message-Id: <1528013536-22196-15-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 04 Jun 2018 14:36:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 04 Jun 2018 14:36:54 +0000 (UTC) for IP:'74.125.83.66' DOMAIN:'mail-pg0-f66.google.com' HELO:'mail-pg0-f66.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.766 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 74.125.83.66 mail-pg0-f66.google.com 74.125.83.66 mail-pg0-f66.google.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 14/18] use VIR_AUTOFREE in src/util/virfile.c 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 04 Jun 2018 15:05:57 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- src/util/virfile.c | 303 +++++++++++++++++--------------------------------= ---- 1 file changed, 99 insertions(+), 204 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 523241f..52b601d 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -211,7 +211,7 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned= int flags) bool output =3D false; int pipefd[2] =3D { -1, -1 }; int mode =3D -1; - char *iohelper_path =3D NULL; + VIR_AUTOFREE(char *) iohelper_path =3D NULL; =20 if (!flags) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -262,8 +262,6 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned= int flags) =20 ret->cmd =3D virCommandNewArgList(iohelper_path, name, NULL); =20 - VIR_FREE(iohelper_path); - if (output) { virCommandSetInputFD(ret->cmd, pipefd[0]); virCommandSetOutputFD(ret->cmd, fd); @@ -294,7 +292,6 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned= int flags) return ret; =20 error: - VIR_FREE(iohelper_path); VIR_FORCE_CLOSE(pipefd[0]); VIR_FORCE_CLOSE(pipefd[1]); virFileWrapperFdFree(ret); @@ -453,7 +450,7 @@ virFileRewrite(const char *path, virFileRewriteFunc rewrite, const void *opaque) { - char *newfile =3D NULL; + VIR_AUTOFREE(char *) newfile =3D NULL; int fd =3D -1; int ret =3D -1; =20 @@ -494,10 +491,8 @@ virFileRewrite(const char *path, =20 cleanup: VIR_FORCE_CLOSE(fd); - if (newfile) { + if (newfile) unlink(newfile); - VIR_FREE(newfile); - } return ret; } =20 @@ -724,7 +719,7 @@ int virFileLoopDeviceAssociate(const char *file, int lofd =3D -1; int fsfd =3D -1; struct loop_info64 lo; - char *loname =3D NULL; + VIR_AUTOFREE(char *) loname =3D NULL; int ret =3D -1; =20 if ((lofd =3D virFileLoopDeviceOpen(&loname)) < 0) @@ -762,7 +757,6 @@ int virFileLoopDeviceAssociate(const char *file, ret =3D 0; =20 cleanup: - VIR_FREE(loname); VIR_FORCE_CLOSE(fsfd); if (ret =3D=3D -1) VIR_FORCE_CLOSE(lofd); @@ -777,8 +771,7 @@ int virFileLoopDeviceAssociate(const char *file, static int virFileNBDDeviceIsBusy(const char *dev_name) { - char *path; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAsprintf(&path, SYSFS_BLOCK_DIR "/%s/pid", dev_name) < 0) @@ -786,18 +779,15 @@ virFileNBDDeviceIsBusy(const char *dev_name) =20 if (!virFileExists(path)) { if (errno =3D=3D ENOENT) - ret =3D 0; + return 0; else virReportSystemError(errno, _("Cannot check NBD device %s pid"), dev_name); - goto cleanup; + return -1; } - ret =3D 1; =20 - cleanup: - VIR_FREE(path); - return ret; + return 1; } =20 =20 @@ -842,15 +832,13 @@ virFileNBDLoadDriver(void) "administratively prohibited")); return false; } else { - char *errbuf =3D NULL; + VIR_AUTOFREE(char *) errbuf =3D NULL; =20 if ((errbuf =3D virKModLoad(NBD_DRIVER, true))) { - VIR_FREE(errbuf); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to load nbd module")); return false; } - VIR_FREE(errbuf); } return true; } @@ -860,8 +848,8 @@ int virFileNBDDeviceAssociate(const char *file, bool readonly, char **dev) { - char *nbddev =3D NULL; - char *qemunbd =3D NULL; + VIR_AUTOFREE(char *) nbddev =3D NULL; + VIR_AUTOFREE(char *) qemunbd =3D NULL; virCommandPtr cmd =3D NULL; int ret =3D -1; const char *fmtstr =3D NULL; @@ -909,8 +897,6 @@ int virFileNBDDeviceAssociate(const char *file, ret =3D 0; =20 cleanup: - VIR_FREE(nbddev); - VIR_FREE(qemunbd); virCommandFree(cmd); return ret; } @@ -957,7 +943,6 @@ int virFileDeleteTree(const char *dir) { DIR *dh; struct dirent *de; - char *filepath =3D NULL; int ret =3D -1; int direrr; =20 @@ -969,6 +954,7 @@ int virFileDeleteTree(const char *dir) return -1; =20 while ((direrr =3D virDirRead(dh, &de, dir)) > 0) { + VIR_AUTOFREE(char *) filepath =3D NULL; struct stat sb; =20 if (virAsprintf(&filepath, "%s/%s", @@ -992,8 +978,6 @@ int virFileDeleteTree(const char *dir) goto cleanup; } } - - VIR_FREE(filepath); } if (direrr < 0) goto cleanup; @@ -1008,7 +992,6 @@ int virFileDeleteTree(const char *dir) ret =3D 0; =20 cleanup: - VIR_FREE(filepath); VIR_DIR_CLOSE(dh); return ret; } @@ -1166,7 +1149,7 @@ static int safezero_slow(int fd, off_t offset, off_t len) { int r; - char *buf; + VIR_AUTOFREE(char *) buf =3D NULL; unsigned long long remain, bytes; =20 if (lseek(fd, offset, SEEK_SET) < 0) @@ -1187,15 +1170,12 @@ safezero_slow(int fd, off_t offset, off_t len) bytes =3D remain; =20 r =3D safewrite(fd, buf, bytes); - if (r < 0) { - VIR_FREE(buf); + if (r < 0) return -1; - } =20 /* safewrite() guarantees all data will be written */ remain -=3D bytes; } - VIR_FREE(buf); return 0; } =20 @@ -1558,8 +1538,7 @@ virFileRelLinkPointsTo(const char *directory, const char *checkLink, const char *checkDest) { - char *candidate; - int ret; + VIR_AUTOFREE(char *) candidate =3D NULL; =20 if (*checkLink =3D=3D '/') return virFileLinkPointsTo(checkLink, checkDest); @@ -1571,9 +1550,8 @@ virFileRelLinkPointsTo(const char *directory, } if (virAsprintf(&candidate, "%s/%s", directory, checkLink) < 0) return -1; - ret =3D virFileLinkPointsTo(candidate, checkDest); - VIR_FREE(candidate); - return ret; + + return virFileLinkPointsTo(candidate, checkDest); } =20 =20 @@ -1897,44 +1875,39 @@ virFileIsExecutable(const char *file) */ int virFileIsMountPoint(const char *file) { - char *parent =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) parent =3D NULL; + int ret; struct stat sb1, sb2; =20 if (!(parent =3D mdir_name(file))) { virReportOOMError(); - goto cleanup; + return -1; } =20 VIR_DEBUG("Comparing '%s' to '%s'", file, parent); =20 if (stat(file, &sb1) < 0) { if (errno =3D=3D ENOENT) - ret =3D 0; + return 0; else virReportSystemError(errno, _("Cannot stat '%s'"), file); - goto cleanup; + return -1; } =20 if (stat(parent, &sb2) < 0) { virReportSystemError(errno, _("Cannot stat '%s'"), parent); - goto cleanup; + return -1; } =20 - if (!S_ISDIR(sb1.st_mode)) { - ret =3D 0; - goto cleanup; - } + if (!S_ISDIR(sb1.st_mode)) + return 0; =20 ret =3D sb1.st_dev !=3D sb2.st_dev; VIR_DEBUG("Is mount %d", ret); - - cleanup: - VIR_FREE(parent); return ret; } =20 @@ -2118,7 +2091,7 @@ virFileAccessibleAs(const char *path, int mode, pid_t pid =3D 0; int status, ret =3D 0; int forkRet =3D 0; - gid_t *groups; + VIR_AUTOFREE(gid_t *) groups =3D NULL; int ngroups; =20 if (uid =3D=3D geteuid() && @@ -2131,13 +2104,10 @@ virFileAccessibleAs(const char *path, int mode, =20 pid =3D virFork(); =20 - if (pid < 0) { - VIR_FREE(groups); + if (pid < 0) return -1; - } =20 if (pid) { /* parent */ - VIR_FREE(groups); if (virProcessWait(pid, &status, false) < 0) { /* virProcessWait() already reported error */ errno =3D EINTR; @@ -2242,7 +2212,7 @@ virFileOpenForked(const char *path, int openflags, mo= de_t mode, int recvfd_errno =3D 0; int fd =3D -1; int pair[2] =3D { -1, -1 }; - gid_t *groups; + VIR_AUTOFREE(gid_t *) groups =3D NULL; int ngroups; bool created =3D false; =20 @@ -2260,16 +2230,12 @@ virFileOpenForked(const char *path, int openflags, = mode_t mode, virReportSystemError(errno, _("failed to create socket needed for '%s'"), path); - VIR_FREE(groups); return ret; } =20 pid =3D virFork(); - if (pid < 0) { - ret =3D -errno; - VIR_FREE(groups); - return ret; - } + if (pid < 0) + return -errno; =20 if (pid =3D=3D 0) { =20 @@ -2334,7 +2300,6 @@ virFileOpenForked(const char *path, int openflags, mo= de_t mode, =20 /* parent */ =20 - VIR_FREE(groups); VIR_FORCE_CLOSE(pair[1]); =20 do { @@ -2535,7 +2500,7 @@ virFileRemove(const char *path, { pid_t pid; int status =3D 0, ret =3D 0; - gid_t *groups; + VIR_AUTOFREE(gid_t *) groups =3D NULL; int ngroups; =20 if (!virFileRemoveNeedsSetuid(path, uid, gid)) { @@ -2560,15 +2525,11 @@ virFileRemove(const char *path, =20 pid =3D virFork(); =20 - if (pid < 0) { - ret =3D -errno; - VIR_FREE(groups); - return ret; - } + if (pid < 0) + return -errno; =20 if (pid) { /* parent */ /* wait for child to complete, and retrieve its exit code */ - VIR_FREE(groups); =20 if (virProcessWait(pid, &status, 0) < 0) { /* virProcessWait() reports errno on waitpid failure, so we'll= just @@ -2700,7 +2661,7 @@ virDirCreate(const char *path, struct stat st; pid_t pid; int status =3D 0, ret =3D 0; - gid_t *groups; + VIR_AUTOFREE(gid_t *) groups =3D NULL; int ngroups; bool created =3D false; =20 @@ -2736,15 +2697,11 @@ virDirCreate(const char *path, =20 pid =3D virFork(); =20 - if (pid < 0) { - ret =3D -errno; - VIR_FREE(groups); - return ret; - } + if (pid < 0) + return -errno; =20 if (pid) { /* parent */ /* wait for child to complete, and retrieve its exit code */ - VIR_FREE(groups); =20 if (virProcessWait(pid, &status, 0) < 0) { /* virProcessWait() reports errno on waitpid failure, so we'll= just @@ -3045,19 +3002,14 @@ int virFileMakePathWithMode(const char *path, mode_t mode) { - int ret =3D -1; - char *tmp; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if (VIR_STRDUP(tmp, path) < 0) { errno =3D ENOMEM; - goto cleanup; + return -1; } =20 - ret =3D virFileMakePathHelper(tmp, mode); - - cleanup: - VIR_FREE(tmp); - return ret; + return virFileMakePathHelper(tmp, mode); } =20 =20 @@ -3065,8 +3017,7 @@ int virFileMakeParentPath(const char *path) { char *p; - char *tmp; - int ret =3D -1; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 VIR_DEBUG("path=3D%s", path); =20 @@ -3077,15 +3028,11 @@ virFileMakeParentPath(const char *path) =20 if ((p =3D strrchr(tmp, '/')) =3D=3D NULL) { errno =3D EINVAL; - goto cleanup; + return -1; } *p =3D '\0'; =20 - ret =3D virFileMakePathHelper(tmp, 0777); - - cleanup: - VIR_FREE(tmp); - return ret; + return virFileMakePathHelper(tmp, 0777); } =20 =20 @@ -3119,7 +3066,7 @@ virFileOpenTty(int *ttymaster, char **ttyName, int ra= wmode) * doesn't have to worry about that mess? */ int ret =3D -1; int slave =3D -1; - char *name =3D NULL; + VIR_AUTOFREE(char *) name =3D NULL; =20 /* Unfortunately, we can't use the name argument of openpty, since * there is no guarantee on how large the buffer has to be. @@ -3180,7 +3127,6 @@ virFileOpenTty(int *ttymaster, char **ttyName, int ra= wmode) if (ret !=3D 0) VIR_FORCE_CLOSE(*ttymaster); VIR_FORCE_CLOSE(slave); - VIR_FREE(name); =20 return ret; } @@ -3280,7 +3226,7 @@ virFileSkipRoot(const char *path) int virFileAbsPath(const char *path, char **abspath) { - char *buf; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if (path[0] =3D=3D '/') { if (VIR_STRDUP(*abspath, path) < 0) @@ -3290,11 +3236,8 @@ virFileAbsPath(const char *path, char **abspath) if (buf =3D=3D NULL) return -1; =20 - if (virAsprintf(abspath, "%s/%s", buf, path) < 0) { - VIR_FREE(buf); + if (virAsprintf(abspath, "%s/%s", buf, path) < 0) return -1; - } - VIR_FREE(buf); } =20 return 0; @@ -3394,7 +3337,7 @@ virFileRemoveLastComponent(char *path) int virFilePrintf(FILE *fp, const char *msg, ...) { va_list vargs; - char *str; + VIR_AUTOFREE(char *) str =3D NULL; int ret; =20 va_start(vargs, msg); @@ -3408,8 +3351,6 @@ int virFilePrintf(FILE *fp, const char *msg, ...) ret =3D -1; } =20 - VIR_FREE(str); - cleanup: va_end(vargs); =20 @@ -3445,7 +3386,8 @@ int virFileIsSharedFSType(const char *path, int fstypes) { - char *dirpath, *p; + VIR_AUTOFREE(char *) dirpath =3D NULL; + char *p; struct statfs sb; int statfs_ret; =20 @@ -3465,7 +3407,6 @@ virFileIsSharedFSType(const char *path, if ((p =3D strrchr(dirpath, '/')) =3D=3D NULL) { virReportSystemError(EINVAL, _("Invalid relative path '%s'"), path); - VIR_FREE(dirpath); return -1; } =20 @@ -3478,8 +3419,6 @@ virFileIsSharedFSType(const char *path, =20 } while ((statfs_ret < 0) && (p !=3D dirpath)); =20 - VIR_FREE(dirpath); - if (statfs_ret < 0) { virReportSystemError(errno, _("cannot determine filesystem for '%s'"), @@ -3546,18 +3485,18 @@ virFileGetHugepageSize(const char *path, static int virFileGetDefaultHugepageSize(unsigned long long *size) { - int ret =3D -1; - char *meminfo, *c, *n, *unit; + VIR_AUTOFREE(char *) meminfo =3D NULL; + char *c, *n, *unit; =20 if (virFileReadAll(PROC_MEMINFO, 4096, &meminfo) < 0) - goto cleanup; + return -1; =20 if (!(c =3D strstr(meminfo, HUGEPAGESIZE_STR))) { virReportError(VIR_ERR_NO_SUPPORT, _("%s not found in %s"), HUGEPAGESIZE_STR, PROC_MEMINFO); - goto cleanup; + return -1; } c +=3D strlen(HUGEPAGESIZE_STR); =20 @@ -3570,13 +3509,10 @@ virFileGetDefaultHugepageSize(unsigned long long *s= ize) virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse %s %s"), HUGEPAGESIZE_STR, c); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(meminfo); - return ret; + return 0; } =20 # define PROC_MOUNTS "/proc/mounts" @@ -3589,7 +3525,7 @@ virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs, FILE *f =3D NULL; struct mntent mb; char mntbuf[1024]; - virHugeTLBFSPtr fs =3D NULL; + VIR_AUTOFREE(virHugeTLBFSPtr) fs =3D NULL; size_t nfs =3D 0; unsigned long long default_hugepagesz =3D 0; =20 @@ -3634,7 +3570,6 @@ virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs, endmntent(f); while (nfs) VIR_FREE(fs[--nfs].mnt_dir); - VIR_FREE(fs); return ret; } =20 @@ -3870,10 +3805,8 @@ virFileCopyACLs(const char *src, int virFileComparePaths(const char *p1, const char *p2) { - int ret =3D -1; - char *res1, *res2; - - res1 =3D res2 =3D NULL; + VIR_AUTOFREE(char *) res1 =3D NULL; + VIR_AUTOFREE(char *) res2 =3D NULL; =20 /* Assume p1 and p2 are symlinks, so try to resolve and canonicalize t= hem. * Canonicalization fails for example on file systems names like 'proc= ' or @@ -3882,19 +3815,13 @@ virFileComparePaths(const char *p1, const char *p2) */ ignore_value(virFileResolveLink(p1, &res1)); if (!res1 && VIR_STRDUP(res1, p1) < 0) - goto cleanup; + return -1; =20 ignore_value(virFileResolveLink(p2, &res2)); if (!res2 && VIR_STRDUP(res2, p2) < 0) - goto cleanup; - - ret =3D STREQ_NULLABLE(res1, res2); - - cleanup: - VIR_FREE(res1); - VIR_FREE(res2); + return -1; =20 - return ret; + return STREQ_NULLABLE(res1, res2); } =20 =20 @@ -4038,25 +3965,22 @@ virFileInData(int fd ATTRIBUTE_UNUSED, int virFileReadValueInt(int *value, const char *format, ...) { - int ret =3D -1; - char *str =3D NULL; - char *path =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; va_list ap; =20 va_start(ap, format); if (virVasprintf(&path, format, ap) < 0) { va_end(ap); - goto cleanup; + return -1; } va_end(ap); =20 - if (!virFileExists(path)) { - ret =3D -2; - goto cleanup; - } + if (!virFileExists(path)) + return -2; =20 if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) - goto cleanup; + return -1; =20 virStringTrimOptionalNewline(str); =20 @@ -4064,14 +3988,10 @@ virFileReadValueInt(int *value, const char *format,= ...) virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid integer value '%s' in file '%s'"), str, path); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(str); - return ret; + return 0; } =20 =20 @@ -4088,25 +4008,22 @@ virFileReadValueInt(int *value, const char *format,= ...) int virFileReadValueUint(unsigned int *value, const char *format, ...) { - int ret =3D -1; - char *str =3D NULL; - char *path =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; va_list ap; =20 va_start(ap, format); if (virVasprintf(&path, format, ap) < 0) { va_end(ap); - goto cleanup; + return -1; } va_end(ap); =20 - if (!virFileExists(path)) { - ret =3D -2; - goto cleanup; - } + if (!virFileExists(path)) + return -2; =20 if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) - goto cleanup; + return -1; =20 virStringTrimOptionalNewline(str); =20 @@ -4114,14 +4031,10 @@ virFileReadValueUint(unsigned int *value, const cha= r *format, ...) virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid unsigned integer value '%s' in file '%s'= "), str, path); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(str); - return ret; + return 0; } =20 =20 @@ -4138,26 +4051,23 @@ virFileReadValueUint(unsigned int *value, const cha= r *format, ...) int virFileReadValueScaledInt(unsigned long long *value, const char *format, .= ..) { - int ret =3D -1; - char *str =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; char *endp =3D NULL; - char *path =3D NULL; va_list ap; =20 va_start(ap, format); if (virVasprintf(&path, format, ap) < 0) { va_end(ap); - goto cleanup; + return -1; } va_end(ap); =20 - if (!virFileExists(path)) { - ret =3D -2; - goto cleanup; - } + if (!virFileExists(path)) + return -2; =20 if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) - goto cleanup; + return -1; =20 virStringTrimOptionalNewline(str); =20 @@ -4165,14 +4075,10 @@ virFileReadValueScaledInt(unsigned long long *value= , const char *format, ...) virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid unsigned scaled integer value '%s' in fi= le '%s'"), str, path); - goto cleanup; + return -1; } =20 - ret =3D virScaleInteger(value, endp, 1024, ULLONG_MAX); - cleanup: - VIR_FREE(path); - VIR_FREE(str); - return ret; + return virScaleInteger(value, endp, 1024, ULLONG_MAX); } =20 /* Arbitrarily sized number, feel free to change, but the function should = be @@ -4192,37 +4098,30 @@ virFileReadValueScaledInt(unsigned long long *value= , const char *format, ...) int virFileReadValueBitmap(virBitmapPtr *value, const char *format, ...) { - int ret =3D -1; - char *str =3D NULL; - char *path =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; va_list ap; =20 va_start(ap, format); if (virVasprintf(&path, format, ap) < 0) { va_end(ap); - goto cleanup; + return -1; } va_end(ap); =20 - if (!virFileExists(path)) { - ret =3D -2; - goto cleanup; - } + if (!virFileExists(path)) + return -2; =20 if (virFileReadAll(path, VIR_FILE_READ_VALUE_STRING_MAX, &str) < 0) - goto cleanup; + return -1; =20 virStringTrimOptionalNewline(str); =20 *value =3D virBitmapParseUnlimited(str); if (!*value) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(str); - return ret; + return 0; } =20 /** @@ -4240,30 +4139,26 @@ virFileReadValueBitmap(virBitmapPtr *value, const c= har *format, ...) int virFileReadValueString(char **value, const char *format, ...) { - int ret =3D -1; - char *str =3D NULL; - char *path =3D NULL; + int ret; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; va_list ap; =20 va_start(ap, format); if (virVasprintf(&path, format, ap) < 0) { va_end(ap); - goto cleanup; + return -1; } va_end(ap); =20 - if (!virFileExists(path)) { - ret =3D -2; - goto cleanup; - } + if (!virFileExists(path)) + return -2; =20 ret =3D virFileReadAll(path, VIR_FILE_READ_VALUE_STRING_MAX, value); =20 if (*value) virStringTrimOptionalNewline(*value); - cleanup: - VIR_FREE(path); - VIR_FREE(str); + return ret; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list