From nobody Fri Apr 26 15:33:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589386979; cv=none; d=zohomail.com; s=zohoarc; b=VQyPWbzXRIH6F9Hl6mp+a0m3bEZiIwGDz6j6VImIWnChsfQ1za5PmfElaql5p8Wkoo3JdM1oIgld9Ka8a+sKcyhRpBYyb2yziYMBtvN3gVZUvC1tiB2drEv8AAGtIGp8mx8c80Igx9dx8VBt05S7FR/N8QWCe4lLy6bdBVobHqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589386979; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ja88aREbukcoXxsPsWU0tS9PbYExM9PFytsYSp3TCic=; b=jMK/UWnb28IshFq1wWedAp0WgNXF4FkuTTbpYP+Mogs/8XCRzC8u+G6c0MR38gDt3iyUcQgdKGJgvkKF2JxtjuDgdoxCJKqLtlufX5DLhNfPLowGTBPs4r/zO1YrHH+WtCvOFGYDYQfZ34xlfFNgSmqK17E8EModrZO/KMwprLk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1589386979916662.327729102126; Wed, 13 May 2020 09:22:59 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-75-uMQ-dZM0PI-1JH9xpMFpbQ-1; Wed, 13 May 2020 12:22:55 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1869B107B266; Wed, 13 May 2020 16:22:50 +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 D8C8510013BD; Wed, 13 May 2020 16:22:48 +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 A3CDB4CAA7; Wed, 13 May 2020 16:22:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04DGMkru006717 for ; Wed, 13 May 2020 12:22:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id F0A811002382; Wed, 13 May 2020 16:22:46 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (unknown [10.33.8.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id C40DB10013BD; Wed, 13 May 2020 16:22:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589386978; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Ja88aREbukcoXxsPsWU0tS9PbYExM9PFytsYSp3TCic=; b=bvJs8chA9kAnN0kXEDAIE8X1172vYH8KtiFxQ7g1zfp3IWTiY6YHaw4d/mj/TtnkW7vZ2I qTZq7Aa9rLHwGWSWHacJtFKkGCanEeSZ3usihWw/zHXJ2Gv1/dd675C9isPf7u1bqf+hqa rfSKJ2VA44nQUbj6WvOF1ZWk8NljR7M= X-MC-Unique: uMQ-dZM0PI-1JH9xpMFpbQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/2] lxc: replace VIR_FREE with g_autofree / g_free Date: Wed, 13 May 2020 17:22:40 +0100 Message-Id: <20200513162241.3929790-2-berrange@redhat.com> In-Reply-To: <20200513162241.3929790-1-berrange@redhat.com> References: <20200513162241.3929790-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com 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: , 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/lxc/lxc_cgroup.c | 14 +-- src/lxc/lxc_conf.c | 15 +-- src/lxc/lxc_container.c | 256 ++++++++++++++------------------------- src/lxc/lxc_controller.c | 126 ++++++++----------- src/lxc/lxc_domain.c | 24 ++-- src/lxc/lxc_driver.c | 60 ++++----- src/lxc/lxc_fuse.c | 8 +- src/lxc/lxc_monitor.c | 7 +- src/lxc/lxc_native.c | 72 ++++++----- src/lxc/lxc_process.c | 124 ++++++++----------- 10 files changed, 269 insertions(+), 437 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 7df723a4da..4ae34925e6 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -387,16 +387,16 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, int *nicindexes) { virCgroupPtr cgroup =3D NULL; - char *machineName =3D virLXCDomainGetMachineName(def, 0); + g_autofree char *machineName =3D virLXCDomainGetMachineName(def, 0); =20 if (!machineName) - goto cleanup; + return NULL; =20 if (def->resource->partition[0] !=3D '/') { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Resource partition '%s' must start with '/'"), def->resource->partition); - goto cleanup; + return NULL; } =20 if (virCgroupNewMachine(machineName, @@ -410,7 +410,7 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, -1, 0, &cgroup) < 0) - goto cleanup; + return NULL; =20 /* setup control group permissions for user namespace */ if (def->idmap.uidmap) { @@ -419,14 +419,10 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, def->idmap.gidmap[0].target, (1 << VIR_CGROUP_CONTROLLER_SYSTEMD)) < 0) { virCgroupFree(&cgroup); - cgroup =3D NULL; - goto cleanup; + return NULL; } } =20 - cleanup: - VIR_FREE(machineName); - return cgroup; } =20 diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 8469f30b9e..43e9b70651 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -62,7 +62,7 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver) virCapsPtr caps; virCapsGuestPtr guest; virArch altArch; - char *lxc_path =3D NULL; + g_autofree char *lxc_path =3D NULL; =20 if ((caps =3D virCapabilitiesNew(virArchFromHost(), false, false)) =3D=3D NULL) @@ -135,8 +135,6 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver) goto error; } =20 - VIR_FREE(lxc_path); - if (driver) { /* Security driver data */ const char *doi, *model, *label, *type; @@ -167,7 +165,6 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver) return caps; =20 error: - VIR_FREE(lxc_path); virObjectUnref(caps); return NULL; } @@ -290,9 +287,9 @@ virLXCDriverConfigDispose(void *obj) { virLXCDriverConfigPtr cfg =3D obj; =20 - VIR_FREE(cfg->configDir); - VIR_FREE(cfg->autostartDir); - VIR_FREE(cfg->stateDir); - VIR_FREE(cfg->logDir); - VIR_FREE(cfg->securityDriverName); + g_free(cfg->configDir); + g_free(cfg->autostartDir); + g_free(cfg->stateDir); + g_free(cfg->logDir); + g_free(cfg->securityDriverName); } diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 1c28ecfdb7..bd78fa7af6 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -136,8 +136,8 @@ int lxcContainerHasReboot(void) CLONE_NEWIPC|SIGCHLD; int cpid; char *childStack; - char *stack; - char *buf; + g_autofree char *stack =3D NULL; + g_autofree char *buf =3D NULL; int cmd, v; int status; char *tmp; @@ -152,10 +152,8 @@ int lxcContainerHasReboot(void) if (virStrToLong_i(buf, NULL, 10, &v) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Malformed ctrl-alt-del setting '%s'"), buf); - VIR_FREE(buf); return -1; } - VIR_FREE(buf); cmd =3D v ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF; =20 if (VIR_ALLOC_N(stack, stacksize) < 0) @@ -164,7 +162,6 @@ int lxcContainerHasReboot(void) childStack =3D stack + stacksize; =20 cpid =3D clone(lxcContainerRebootChild, childStack, flags, &cmd); - VIR_FREE(stack); if (cpid < 0) { virReportSystemError(errno, "%s", _("Unable to clone to check reboot support")); @@ -638,7 +635,7 @@ static int lxcContainerResolveSymlinks(virDomainFSDefPt= r fs, bool gentle) =20 VIR_DEBUG("Resolved '%s' to %s", fs->src->path, newroot); =20 - VIR_FREE(fs->src->path); + g_free(fs->src->path); fs->src->path =3D newroot; =20 return 0; @@ -648,7 +645,7 @@ static int lxcContainerPrepareRoot(virDomainDefPtr def, virDomainFSDefPtr root, const char *sec_mount_options) { - char *dst; + g_autofree char *dst =3D NULL; char *tmp; =20 VIR_DEBUG("Prepare root %d", root->type); @@ -679,24 +676,21 @@ static int lxcContainerPrepareRoot(virDomainDefPtr de= f, =20 if (lxcContainerMountFSBlock(root, "", sec_mount_options) < 0) { root->dst =3D tmp; - VIR_FREE(dst); return -1; } =20 root->dst =3D tmp; root->type =3D VIR_DOMAIN_FS_TYPE_MOUNT; - VIR_FREE(root->src->path); - root->src->path =3D dst; + g_free(root->src->path); + root->src->path =3D g_steal_pointer(&dst); =20 return 0; } =20 static int lxcContainerPivotRoot(virDomainFSDefPtr root) { - int ret; - char *oldroot =3D NULL, *newroot =3D NULL; - - ret =3D -1; + g_autofree char *oldroot =3D NULL; + g_autofree char *newroot =3D NULL; =20 VIR_DEBUG("Pivot via %s", root->src->path); =20 @@ -704,7 +698,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root) if (mount("", "/", "none", MS_PRIVATE|MS_REC, NULL) < 0) { virReportSystemError(errno, "%s", _("Failed to make root private")); - goto err; + return -1; } =20 oldroot =3D g_strdup_printf("%s/.oldroot", root->src->path); @@ -713,7 +707,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root) virReportSystemError(errno, _("Failed to create %s"), oldroot); - goto err; + return -1; } =20 /* Create a tmpfs root since old and new roots must be @@ -722,7 +716,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root) virReportSystemError(errno, _("Failed to mount empty tmpfs at %s"), oldroot); - goto err; + return -1; } =20 /* Create a directory called 'new' in tmpfs */ @@ -732,7 +726,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root) virReportSystemError(errno, _("Failed to create %s"), newroot); - goto err; + return -1; } =20 /* ... and mount our root onto it */ @@ -740,7 +734,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root) virReportSystemError(errno, _("Failed to bind %s to new root %s"), root->src->path, newroot); - goto err; + return -1; } =20 if (root->readonly) { @@ -748,7 +742,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root) virReportSystemError(errno, _("Failed to make new root %s readonly"), root->src->path); - goto err; + return -1; } } =20 @@ -757,7 +751,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root) if (chdir(newroot) < 0) { virReportSystemError(errno, _("Failed to chdir into %s"), newroot); - goto err; + return -1; } =20 /* The old root directory will live at /.oldroot after @@ -765,20 +759,14 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr ro= ot) if (pivot_root(".", ".oldroot") < 0) { virReportSystemError(errno, "%s", _("Failed to pivot root")); - goto err; + return -1; } =20 /* CWD is undefined after pivot_root, so go to / */ if (chdir("/") < 0) - goto err; - - ret =3D 0; - - err: - VIR_FREE(oldroot); - VIR_FREE(newroot); + return -1; =20 - return ret; + return 0; } =20 =20 @@ -845,7 +833,7 @@ static int lxcContainerSetReadOnly(void) tmp =3D g_strdup(mntent.mnt_dir); =20 if (VIR_APPEND_ELEMENT(mounts, nmounts, tmp) < 0) { - VIR_FREE(tmp); + g_free(tmp); goto cleanup; } } @@ -881,13 +869,12 @@ static int lxcContainerMountBasicFS(bool userns_enabl= ed, bool netns_disabled) { size_t i; - int rc =3D -1; - char* mnt_src =3D NULL; int mnt_mflags; =20 VIR_DEBUG("Mounting basic filesystems"); =20 for (i =3D 0; i < G_N_ELEMENTS(lxcBasicMounts); i++) { + g_autofree char *mnt_src =3D NULL; bool bindOverReadonly; virLXCBasicMountInfo const *mnt =3D &lxcBasicMounts[i]; =20 @@ -908,27 +895,23 @@ static int lxcContainerMountBasicFS(bool userns_enabl= ed, mnt_src, mnt->dst); =20 if (mnt->skipUnmounted) { - char *hostdir; int ret; - - hostdir =3D g_strdup_printf("/.oldroot%s", mnt->dst); + g_autofree char *hostdir =3D g_strdup_printf("/.oldroot%s", + mnt->dst); =20 ret =3D virFileIsMountPoint(hostdir); - VIR_FREE(hostdir); if (ret < 0) - goto cleanup; + return -1; =20 if (ret =3D=3D 0) { VIR_DEBUG("Skipping '%s' which isn't mounted in host", mnt->dst); - VIR_FREE(mnt_src); continue; } } =20 if (mnt->skipUserNS && userns_enabled) { VIR_DEBUG("Skipping due to user ns enablement"); - VIR_FREE(mnt_src); continue; } =20 @@ -936,13 +919,11 @@ static int lxcContainerMountBasicFS(bool userns_enabl= ed, * missing folder in /proc due to the absence of a kernel feature = */ if (STRPREFIX(mnt_src, "/") && !virFileExists(mnt_src)) { VIR_DEBUG("Skipping due to missing source: %s", mnt_src); - VIR_FREE(mnt_src); continue; } =20 if (mnt->skipNoNetns && netns_disabled) { VIR_DEBUG("Skipping due to absence of network namespace"); - VIR_FREE(mnt_src); continue; } =20 @@ -950,7 +931,7 @@ static int lxcContainerMountBasicFS(bool userns_enabled, virReportSystemError(errno, _("Failed to mkdir %s"), mnt->dst); - goto cleanup; + return -1; } =20 /* @@ -969,7 +950,7 @@ static int lxcContainerMountBasicFS(bool userns_enabled, _("Failed to mount %s on %s type %s flags= =3D0x%x"), mnt_src, mnt->dst, NULLSTR(mnt->type), mnt_mflags & ~MS_RDONLY); - goto cleanup; + return -1; } =20 if (bindOverReadonly && @@ -979,26 +960,18 @@ static int lxcContainerMountBasicFS(bool userns_enabl= ed, _("Failed to re-mount %s on %s flags=3D0x= %x"), mnt_src, mnt->dst, MS_BIND|MS_REMOUNT|MS_RDONLY); - goto cleanup; + return -1; } - - VIR_FREE(mnt_src); } =20 - rc =3D 0; - - cleanup: - VIR_FREE(mnt_src); - VIR_DEBUG("rc=3D%d", rc); - return rc; + return 0; } =20 #if WITH_FUSE static int lxcContainerMountProcFuse(virDomainDefPtr def, const char *stateDir) { - int ret; - char *meminfo_path =3D NULL; + g_autofree char *meminfo_path =3D NULL; =20 VIR_DEBUG("Mount /proc/meminfo stateDir=3D%s", stateDir); =20 @@ -1006,15 +979,15 @@ static int lxcContainerMountProcFuse(virDomainDefPtr= def, stateDir, def->name); =20 - if ((ret =3D mount(meminfo_path, "/proc/meminfo", - NULL, MS_BIND, NULL)) < 0) { + if (mount(meminfo_path, "/proc/meminfo", + NULL, MS_BIND, NULL) < 0) { virReportSystemError(errno, _("Failed to mount %s on /proc/meminfo"), meminfo_path); + return -1; } =20 - VIR_FREE(meminfo_path); - return ret; + return 0; } #else static int lxcContainerMountProcFuse(virDomainDefPtr def G_GNUC_UNUSED, @@ -1027,8 +1000,7 @@ static int lxcContainerMountProcFuse(virDomainDefPtr = def G_GNUC_UNUSED, static int lxcContainerMountFSDev(virDomainDefPtr def, const char *stateDir) { - int ret =3D -1; - char *path =3D NULL; + g_autofree char *path =3D NULL; int flags =3D def->idmap.nuidmap ? MS_BIND : MS_MOVE; =20 VIR_DEBUG("Mount /dev/ stateDir=3D%s", stateDir); @@ -1038,7 +1010,7 @@ static int lxcContainerMountFSDev(virDomainDefPtr def, if (virFileMakePath("/dev") < 0) { virReportSystemError(errno, "%s", _("Cannot create /dev")); - goto cleanup; + return -1; } =20 VIR_DEBUG("Trying to %s %s to /dev", def->idmap.nuidmap ? @@ -1048,21 +1020,16 @@ static int lxcContainerMountFSDev(virDomainDefPtr d= ef, virReportSystemError(errno, _("Failed to mount %s on /dev"), path); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(path); - return ret; + return 0; } =20 static int lxcContainerMountFSDevPTS(virDomainDefPtr def, const char *stateDir) { - int ret =3D -1; - char *path =3D NULL; + g_autofree char *path =3D NULL; int flags =3D def->idmap.nuidmap ? MS_BIND : MS_MOVE; =20 VIR_DEBUG("Mount /dev/pts stateDir=3D%s", stateDir); @@ -1072,7 +1039,7 @@ static int lxcContainerMountFSDevPTS(virDomainDefPtr = def, if (virFileMakePath("/dev/pts") < 0) { virReportSystemError(errno, "%s", _("Cannot create /dev/pts")); - goto cleanup; + return -1; } =20 VIR_DEBUG("Trying to %s %s to /dev/pts", def->idmap.nuidmap ? @@ -1082,13 +1049,10 @@ static int lxcContainerMountFSDevPTS(virDomainDefPt= r def, virReportSystemError(errno, _("Failed to mount %s on /dev/pts"), path); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - return ret; + return 0; } =20 static int lxcContainerSetupDevices(char **ttyPaths, size_t nttyPaths) @@ -1118,15 +1082,10 @@ static int lxcContainerSetupDevices(char **ttyPaths= , size_t nttyPaths) return -1; =20 for (i =3D 0; i < nttyPaths; i++) { - char *tty; - tty =3D g_strdup_printf("/dev/tty%zu", i + 1); + g_autofree char *tty =3D g_strdup_printf("/dev/tty%zu", i + 1); =20 - if (virFileBindMountDevice(ttyPaths[i], tty) < 0) { - VIR_FREE(tty); + if (virFileBindMountDevice(ttyPaths[i], tty) < 0) return -1; - } - - VIR_FREE(tty); =20 if (i =3D=3D 0 && virFileBindMountDevice(ttyPaths[i], "/dev/console") < 0) @@ -1139,8 +1098,7 @@ static int lxcContainerSetupDevices(char **ttyPaths, = size_t nttyPaths) static int lxcContainerMountFSBind(virDomainFSDefPtr fs, const char *srcprefix) { - char *src =3D NULL; - int ret =3D -1; + g_autofree char *src =3D NULL; struct stat st; =20 VIR_DEBUG("src=3D%s dst=3D%s", fs->src->path, fs->dst); @@ -1151,20 +1109,20 @@ static int lxcContainerMountFSBind(virDomainFSDefPt= r fs, if (errno !=3D ENOENT) { virReportSystemError(errno, _("Unable to stat bind target %s"), fs->dst); - goto cleanup; + return -1; } /* ENOENT =3D> create the target dir or file */ if (stat(src, &st) < 0) { virReportSystemError(errno, _("Unable to stat bind source %s"), src); - goto cleanup; + return -1; } if (S_ISDIR(st.st_mode)) { if (virFileMakePath(fs->dst) < 0) { virReportSystemError(errno, _("Failed to create %s"), fs->dst); - goto cleanup; + return -1; } } else { /* Create Empty file for target mount point */ @@ -1174,14 +1132,14 @@ static int lxcContainerMountFSBind(virDomainFSDefPt= r fs, virReportSystemError(errno, _("Failed to create bind target %= s"), fs->dst); - goto cleanup; + return -1; } } if (VIR_CLOSE(fd) < 0) { virReportSystemError(errno, _("Failed to close bind target %s"), fs->dst); - goto cleanup; + return -1; } } } @@ -1190,7 +1148,7 @@ static int lxcContainerMountFSBind(virDomainFSDefPtr = fs, virReportSystemError(errno, _("Failed to bind mount directory %s to %s"), src, fs->dst); - goto cleanup; + return -1; } =20 if (fs->readonly) { @@ -1202,11 +1160,7 @@ static int lxcContainerMountFSBind(virDomainFSDefPtr= fs, } } =20 - ret =3D 0; - - cleanup: - VIR_FREE(src); - return ret; + return 0; } =20 =20 @@ -1307,14 +1261,14 @@ static int lxcContainerMountFSBlockAuto(virDomainFS= DefPtr fs, int ret =3D -1; bool tryProc =3D false; bool gotStar =3D false; - char *fslist =3D NULL; - char *line =3D NULL; + g_autofree char *fslist =3D NULL; const char *type; =20 VIR_DEBUG("src=3D%s dst=3D%s srcprefix=3D%s", src, fs->dst, srcprefix); =20 /* First time around we use /etc/filesystems */ retry: + g_free(fslist); fslist =3D g_strdup_printf("%s%s", srcprefix, tryProc ? "/proc/filesystems" : "/etc/filesys= tems"); =20 @@ -1326,7 +1280,6 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDe= fPtr fs, if (errno =3D=3D ENOENT && !tryProc) { tryProc =3D true; - VIR_FREE(fslist); goto retry; } =20 @@ -1337,8 +1290,8 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDe= fPtr fs, } =20 while (!feof(fp)) { + g_autofree char *line =3D NULL; size_t n; - VIR_FREE(line); if (getline(&line, &n, fp) <=3D 0) { if (feof(fp)) break; @@ -1401,7 +1354,6 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDe= fPtr fs, !tryProc && gotStar) { tryProc =3D true; - VIR_FREE(fslist); VIR_FORCE_FCLOSE(fp); goto retry; } @@ -1415,8 +1367,6 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDe= fPtr fs, VIR_DEBUG("Done mounting filesystem ret=3D%d tryProc=3D%d", ret, tryPr= oc); =20 cleanup: - VIR_FREE(line); - VIR_FREE(fslist); VIR_FORCE_FCLOSE(fp); return ret; } @@ -1432,8 +1382,7 @@ static int lxcContainerMountFSBlockHelper(virDomainFS= DefPtr fs, const char *sec_mount_options) { int fsflags =3D 0; - int ret =3D -1; - char *format =3D NULL; + g_autofree char *format =3D NULL; =20 if (fs->readonly) fsflags |=3D MS_RDONLY; @@ -1442,11 +1391,11 @@ static int lxcContainerMountFSBlockHelper(virDomain= FSDefPtr fs, virReportSystemError(errno, _("Failed to create %s"), fs->dst); - goto cleanup; + return -1; } =20 if (lxcContainerMountDetectFilesystem(src, &format) < 0) - goto cleanup; + return -1; =20 if (format) { VIR_DEBUG("Mount '%s' on '%s' with detected format '%s' opts '%s'", @@ -1455,16 +1404,12 @@ static int lxcContainerMountFSBlockHelper(virDomain= FSDefPtr fs, virReportSystemError(errno, _("Failed to mount device %s to %s as %s"= ), src, fs->dst, format); - goto cleanup; + return -1; } - ret =3D 0; + return 0; } else { - ret =3D lxcContainerMountFSBlockAuto(fs, fsflags, src, srcprefix, = sec_mount_options); + return lxcContainerMountFSBlockAuto(fs, fsflags, src, srcprefix, s= ec_mount_options); } - - cleanup: - VIR_FREE(format); - return ret; } =20 =20 @@ -1472,7 +1417,7 @@ static int lxcContainerMountFSBlock(virDomainFSDefPtr= fs, const char *srcprefix, const char *sec_mount_options) { - char *src =3D NULL; + g_autofree char *src =3D NULL; int ret =3D -1; =20 VIR_DEBUG("src=3D%s dst=3D%s", fs->src->path, fs->dst); @@ -1483,7 +1428,6 @@ static int lxcContainerMountFSBlock(virDomainFSDefPtr= fs, =20 VIR_DEBUG("Done mounting filesystem ret=3D%d", ret); =20 - VIR_FREE(src); return ret; } =20 @@ -1491,8 +1435,7 @@ static int lxcContainerMountFSBlock(virDomainFSDefPtr= fs, static int lxcContainerMountFSTmpfs(virDomainFSDefPtr fs, char *sec_mount_options) { - int ret =3D -1; - char *data =3D NULL; + g_autofree char *data =3D NULL; =20 VIR_DEBUG("usage=3D%lld sec=3D%s", fs->usage, sec_mount_options); =20 @@ -1502,14 +1445,14 @@ static int lxcContainerMountFSTmpfs(virDomainFSDefP= tr fs, virReportSystemError(errno, _("Failed to create %s"), fs->dst); - goto cleanup; + return -1; } =20 if (mount("tmpfs", fs->dst, "tmpfs", MS_NOSUID|MS_NODEV, data) < 0) { virReportSystemError(errno, _("Failed to mount directory %s as tmpfs"), fs->dst); - goto cleanup; + return -1; } =20 if (fs->readonly) { @@ -1518,15 +1461,11 @@ static int lxcContainerMountFSTmpfs(virDomainFSDefP= tr fs, virReportSystemError(errno, _("Failed to make directory %s readonly"), fs->dst); - goto cleanup; + return -1; } } =20 - ret =3D 0; - - cleanup: - VIR_FREE(data); - return ret; + return 0; } =20 =20 @@ -1600,8 +1539,8 @@ static int lxcContainerMountAllFS(virDomainDefPtr vmD= ef, =20 int lxcContainerSetupHostdevCapsMakePath(const char *dev) { - int ret =3D -1; - char *dir, *tmp; + g_autofree char *dir =3D NULL; + char *tmp; =20 dir =3D g_strdup(dev); =20 @@ -1611,30 +1550,25 @@ int lxcContainerSetupHostdevCapsMakePath(const char= *dev) virReportSystemError(errno, _("Failed to create directory for '%s' de= v '%s'"), dir, dev); - goto cleanup; + return -1; } } =20 - ret =3D 0; - - cleanup: - VIR_FREE(dir); - return ret; + return 0; } =20 =20 static int lxcContainerUnmountForSharedRoot(const char *stateDir, const char *domain) { - int ret =3D -1; - char *tmp =3D NULL; + g_autofree char *tmp =3D NULL; =20 #if WITH_SELINUX /* Some versions of Linux kernel don't let you overmount * the selinux filesystem, so make sure we kill it first */ if (lxcContainerUnmountSubtree(SELINUX_MOUNT, false) < 0) - goto cleanup; + return -1; #endif =20 /* These filesystems are created by libvirt temporarily, they @@ -1642,20 +1576,20 @@ static int lxcContainerUnmountForSharedRoot(const c= har *stateDir, tmp =3D g_strdup_printf("%s/%s.dev", stateDir, domain); =20 if (lxcContainerUnmountSubtree(tmp, false) < 0) - goto cleanup; + return -1; =20 - VIR_FREE(tmp); + g_free(tmp); tmp =3D g_strdup_printf("%s/%s.devpts", stateDir, domain); =20 if (lxcContainerUnmountSubtree(tmp, false) < 0) - goto cleanup; + return -1; =20 #if WITH_FUSE - VIR_FREE(tmp); + g_free(tmp); tmp =3D g_strdup_printf("%s/%s.fuse", stateDir, domain); =20 if (lxcContainerUnmountSubtree(tmp, false) < 0) - goto cleanup; + return -1; #endif =20 /* If we have the root source being '/', then we need to @@ -1665,13 +1599,9 @@ static int lxcContainerUnmountForSharedRoot(const ch= ar *stateDir, if (lxcContainerUnmountSubtree("/sys", false) < 0 || lxcContainerUnmountSubtree("/dev", false) < 0 || lxcContainerUnmountSubtree("/proc", false) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(tmp); - return ret; + return 0; } =20 =20 @@ -1704,8 +1634,8 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr= vmDef, { virCgroupPtr cgroup =3D NULL; int ret =3D -1; - char *sec_mount_options; - char *stateDir =3D NULL; + g_autofree char *sec_mount_options =3D NULL; + g_autofree char *stateDir =3D NULL; =20 VIR_DEBUG("Setup pivot root"); =20 @@ -1776,9 +1706,7 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr= vmDef, ret =3D 0; =20 cleanup: - VIR_FREE(stateDir); virCgroupFree(&cgroup); - VIR_FREE(sec_mount_options); return ret; } =20 @@ -2128,9 +2056,8 @@ static const char hostname_validchars[] =3D =20 static int lxcContainerSetHostname(virDomainDefPtr def) { - int ret =3D -1; - char *name =3D NULL; - char *hostname =3D NULL; + g_autofree char *name =3D NULL; + const char *hostname =3D NULL; =20 /* Filter the VM name to get a valid hostname */ name =3D g_strdup(def->name); @@ -2143,13 +2070,10 @@ static int lxcContainerSetHostname(virDomainDefPtr = def) =20 if (sethostname(hostname, strlen(hostname)) < 0) { virReportSystemError(errno, "%s", _("Failed to set hostname")); - goto cleanup; + return -1; } - ret =3D 0; =20 - cleanup: - VIR_FREE(name); - return ret; + return 0; } =20 /** @@ -2170,11 +2094,11 @@ static int lxcContainerChild(void *data) virDomainDefPtr vmDef =3D argv->config; int ttyfd =3D -1; int ret =3D -1; - char *ttyPath =3D NULL; + g_autofree char *ttyPath =3D NULL; virDomainFSDefPtr root; virCommandPtr cmd =3D NULL; int hasReboot; - gid_t *groups =3D NULL; + g_autofree gid_t *groups =3D NULL; int ngroups; =20 if (NULL =3D=3D vmDef) { @@ -2303,7 +2227,6 @@ static int lxcContainerChild(void *data) =20 ret =3D 0; cleanup: - VIR_FREE(ttyPath); VIR_FORCE_CLOSE(ttyfd); VIR_FORCE_CLOSE(argv->monitor); VIR_FORCE_CLOSE(argv->handshakefd); @@ -2321,7 +2244,6 @@ static int lxcContainerChild(void *data) virGetLastErrorMessage()); } =20 - VIR_FREE(groups); virCommandFree(cmd); return ret; } @@ -2383,7 +2305,8 @@ int lxcContainerStart(virDomainDefPtr def, pid_t pid; int cflags; int stacksize =3D getpagesize() * 4; - char *stack, *stacktop; + g_autofree char *stack =3D NULL; + char *stacktop; lxc_child_argv_t args =3D { .config =3D def, .securityDriver =3D securityDriver, @@ -2410,7 +2333,6 @@ int lxcContainerStart(virDomainDefPtr def, if (virProcessNamespaceAvailable(VIR_PROCESS_NAMESPACE_USER) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Kernel doesn't support user namespace")); - VIR_FREE(stack); return -1; } VIR_DEBUG("Enable user namespace"); @@ -2426,7 +2348,6 @@ int lxcContainerStart(virDomainDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Config asks for inherit net namespace " "as well as private network interfaces")); - VIR_FREE(stack); return -1; } VIR_DEBUG("Inheriting a net namespace"); @@ -2446,7 +2367,6 @@ int lxcContainerStart(virDomainDefPtr def, =20 VIR_DEBUG("Cloning container init process"); pid =3D clone(lxcContainerChild, stacktop, cflags, &args); - VIR_FREE(stack); VIR_DEBUG("clone() completed, new container PID is %d", pid); =20 if (pid < 0) { diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 453b435dd6..0438d72538 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -191,7 +191,7 @@ static virLXCControllerPtr virLXCControllerNew(const ch= ar *name) { virLXCControllerPtr ctrl =3D NULL; virLXCDriverPtr driver =3D NULL; - char *configFile =3D NULL; + g_autofree char *configFile =3D NULL; =20 if (VIR_ALLOC(ctrl) < 0) goto error; @@ -220,7 +220,6 @@ static virLXCControllerPtr virLXCControllerNew(const ch= ar *name) goto error; =20 cleanup: - VIR_FREE(configFile); virLXCControllerDriverFree(driver); return ctrl; =20 @@ -288,22 +287,22 @@ static void virLXCControllerFree(virLXCControllerPtr = ctrl) virObjectUnref(ctrl->securityManager); =20 for (i =3D 0; i < ctrl->nveths; i++) - VIR_FREE(ctrl->veths[i]); - VIR_FREE(ctrl->veths); - VIR_FREE(ctrl->nicindexes); + g_free(ctrl->veths[i]); + g_free(ctrl->veths); + g_free(ctrl->nicindexes); =20 for (i =3D 0; i < ctrl->npassFDs; i++) VIR_FORCE_CLOSE(ctrl->passFDs[i]); - VIR_FREE(ctrl->passFDs); + g_free(ctrl->passFDs); =20 for (i =3D 0; i < ctrl->nconsoles; i++) virLXCControllerConsoleClose(&(ctrl->consoles[i])); - VIR_FREE(ctrl->consoles); + g_free(ctrl->consoles); =20 - VIR_FREE(ctrl->devptmx); + g_free(ctrl->devptmx); =20 virDomainObjEndAPI(&ctrl->vm); - VIR_FREE(ctrl->name); + g_free(ctrl->name); =20 if (ctrl->timerShutdown !=3D -1) virEventRemoveTimeout(ctrl->timerShutdown); @@ -311,14 +310,14 @@ static void virLXCControllerFree(virLXCControllerPtr = ctrl) virObjectUnref(ctrl->daemon); virLXCControllerFreeFuse(ctrl); =20 - VIR_FREE(ctrl->nbdpids); + g_free(ctrl->nbdpids); =20 - VIR_FREE(ctrl->nsFDs); + g_free(ctrl->nsFDs); virCgroupFree(&ctrl->cgroup); =20 /* This must always be the last thing to be closed */ VIR_FORCE_CLOSE(ctrl->handshakeFd); - VIR_FREE(ctrl); + g_free(ctrl); } =20 =20 @@ -469,7 +468,7 @@ static int virLXCControllerSetupLoopDeviceFS(virDomainF= SDefPtr fs) * the rest of container setup 'just works' */ fs->type =3D VIR_DOMAIN_FS_TYPE_BLOCK; - VIR_FREE(fs->src->path); + g_free(fs->src->path); fs->src->path =3D loname; loname =3D NULL; =20 @@ -480,7 +479,7 @@ static int virLXCControllerSetupLoopDeviceFS(virDomainF= SDefPtr fs) static int virLXCControllerSetupLoopDeviceDisk(virDomainDiskDefPtr disk) { int lofd; - char *loname =3D NULL; + g_autofree char *loname =3D NULL; const char *src =3D virDomainDiskGetSource(disk); int ret =3D -1; =20 @@ -501,7 +500,6 @@ static int virLXCControllerSetupLoopDeviceDisk(virDomai= nDiskDefPtr disk) ret =3D 0; =20 cleanup: - VIR_FREE(loname); if (ret < 0) VIR_FORCE_CLOSE(lofd); =20 @@ -533,7 +531,7 @@ static int virLXCControllerSetupNBDDeviceFS(virDomainFS= DefPtr fs) * the rest of container setup 'just works' */ fs->type =3D VIR_DOMAIN_FS_TYPE_BLOCK; - VIR_FREE(fs->src->path); + g_free(fs->src->path); fs->src->path =3D dev; =20 return 0; @@ -542,7 +540,7 @@ static int virLXCControllerSetupNBDDeviceFS(virDomainFS= DefPtr fs) =20 static int virLXCControllerSetupNBDDeviceDisk(virDomainDiskDefPtr disk) { - char *dev; + g_autofree char *dev =3D NULL; const char *src =3D virDomainDiskGetSource(disk); int format =3D virDomainDiskGetFormat(disk); =20 @@ -565,11 +563,8 @@ static int virLXCControllerSetupNBDDeviceDisk(virDomai= nDiskDefPtr disk) * the rest of container setup 'just works' */ virDomainDiskSetType(disk, VIR_STORAGE_TYPE_BLOCK); - if (virDomainDiskSetSource(disk, dev) < 0) { - VIR_FREE(dev); + if (virDomainDiskSetSource(disk, dev) < 0) return -1; - } - VIR_FREE(dev); =20 return 0; } @@ -577,16 +572,15 @@ static int virLXCControllerSetupNBDDeviceDisk(virDoma= inDiskDefPtr disk) static int virLXCControllerAppendNBDPids(virLXCControllerPtr ctrl, const char *dev) { - char *pidpath =3D NULL; - pid_t *pids =3D NULL; + g_autofree char *pidpath =3D NULL; + g_autofree pid_t *pids =3D NULL; size_t npids =3D 0; size_t i; - int ret =3D -1; size_t loops =3D 0; pid_t pid; =20 if (!STRPREFIX(dev, "/dev/")) - goto cleanup; + return -1; =20 pidpath =3D g_strdup_printf("/sys/devices/virtual/block/%s/pid", dev += 5); =20 @@ -600,27 +594,22 @@ static int virLXCControllerAppendNBDPids(virLXCContro= llerPtr ctrl, virReportSystemError(errno, _("Cannot check NBD device %s pid"), dev + 5); - goto cleanup; + return -1; } } =20 if (virPidFileReadPath(pidpath, &pid) < 0) - goto cleanup; + return -1; =20 if (virProcessGetPids(pid, &npids, &pids) < 0) - goto cleanup; + return -1; =20 for (i =3D 0; i < npids; i++) { if (VIR_APPEND_ELEMENT(ctrl->nbdpids, ctrl->nnbdpids, pids[i]) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(pids); - VIR_FREE(pidpath); - return ret; + return 0; } =20 static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl) @@ -957,7 +946,7 @@ static int virLXCControllerSetupServer(virLXCController= Ptr ctrl) { virNetServerPtr srv =3D NULL; virNetServerServicePtr svc =3D NULL; - char *sockpath; + g_autofree char *sockpath =3D NULL; =20 sockpath =3D g_strdup_printf("%s/%s.sock", LXC_STATE_DIR, ctrl->name); =20 @@ -1002,11 +991,9 @@ static int virLXCControllerSetupServer(virLXCControll= erPtr ctrl) goto error; =20 virNetDaemonUpdateServices(ctrl->daemon, true); - VIR_FREE(sockpath); return 0; =20 error: - VIR_FREE(sockpath); virObjectUnref(srv); virObjectUnref(ctrl->daemon); ctrl->daemon =3D NULL; @@ -1606,11 +1593,10 @@ virLXCControllerSetupHostdevSubsysUSB(virDomainDefP= tr vmDef, virDomainHostdevDefPtr def, virSecurityManagerPtr securityDriver) { - int ret =3D -1; - char *src =3D NULL; - char *dstdir =3D NULL; - char *dstfile =3D NULL; - char *vroot =3D NULL; + g_autofree char *src =3D NULL; + g_autofree char *dstdir =3D NULL; + g_autofree char *dstfile =3D NULL; + g_autofree char *vroot =3D NULL; struct stat sb; mode_t mode; virDomainHostdevSubsysUSBPtr usbsrc =3D &def->source.subsys.u.usb; @@ -1626,14 +1612,14 @@ virLXCControllerSetupHostdevSubsysUSB(virDomainDefP= tr vmDef, if (stat(src, &sb) < 0) { virReportSystemError(errno, _("Unable to access %s"), src); - goto cleanup; + return -1; } =20 if (!S_ISCHR(sb.st_mode)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("USB source %s was not a character device"), src); - goto cleanup; + return -1; } =20 mode =3D 0700 | S_IFCHR; @@ -1641,7 +1627,7 @@ virLXCControllerSetupHostdevSubsysUSB(virDomainDefPtr= vmDef, if (virFileMakePath(dstdir) < 0) { virReportSystemError(errno, _("Unable to create %s"), dstdir); - goto cleanup; + return -1; } =20 VIR_DEBUG("Creating dev %s (%d,%d)", @@ -1650,24 +1636,17 @@ virLXCControllerSetupHostdevSubsysUSB(virDomainDefP= tr vmDef, virReportSystemError(errno, _("Unable to create device %s"), dstfile); - goto cleanup; + return -1; } =20 if (lxcContainerChown(vmDef, dstfile) < 0) - goto cleanup; + return -1; =20 if (virSecurityManagerSetHostdevLabel(securityDriver, vmDef, def, vroot) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(src); - VIR_FREE(dstfile); - VIR_FREE(dstdir); - VIR_FREE(vroot); - return ret; + return 0; } =20 =20 @@ -1676,8 +1655,8 @@ virLXCControllerSetupHostdevCapsStorage(virDomainDefP= tr vmDef, virDomainHostdevDefPtr def, virSecurityManagerPtr securityDriv= er) { - char *dst =3D NULL; - char *path =3D NULL; + g_autofree char *dst =3D NULL; + g_autofree char *path =3D NULL; int len =3D 0; int ret =3D -1; struct stat sb; @@ -1741,8 +1720,6 @@ virLXCControllerSetupHostdevCapsStorage(virDomainDefP= tr vmDef, =20 cleanup: def->source.caps.u.storage.block =3D dev; - VIR_FREE(dst); - VIR_FREE(path); return ret; } =20 @@ -1752,8 +1729,8 @@ virLXCControllerSetupHostdevCapsMisc(virDomainDefPtr = vmDef, virDomainHostdevDefPtr def, virSecurityManagerPtr securityDriver) { - char *dst =3D NULL; - char *path =3D NULL; + g_autofree char *dst =3D NULL; + g_autofree char *path =3D NULL; int len =3D 0; int ret =3D -1; struct stat sb; @@ -1817,8 +1794,6 @@ virLXCControllerSetupHostdevCapsMisc(virDomainDefPtr = vmDef, =20 cleanup: def->source.caps.u.misc.chardev =3D dev; - VIR_FREE(dst); - VIR_FREE(path); return ret; } =20 @@ -1910,7 +1885,7 @@ static int virLXCControllerSetupDisk(virLXCController= Ptr ctrl, virDomainDiskDefPtr def, virSecurityManagerPtr securityDriver) { - char *dst =3D NULL; + g_autofree char *dst =3D NULL; int ret =3D -1; struct stat sb; mode_t mode; @@ -1979,7 +1954,6 @@ static int virLXCControllerSetupDisk(virLXCController= Ptr ctrl, =20 cleanup: def->src->path =3D tmpsrc; - VIR_FREE(dst); return ret; } =20 @@ -2125,7 +2099,8 @@ lxcCreateTty(virLXCControllerPtr ctrl, int *ttymaster, cleanup: if (ret !=3D 0) { VIR_FORCE_CLOSE(*ttymaster); - VIR_FREE(*ttyName); + g_free(*ttyName); + *ttyName =3D NULL; } =20 return ret; @@ -2233,9 +2208,10 @@ virLXCControllerSetupConsoles(virLXCControllerPtr ct= rl, char **containerTTYPaths) { size_t i; - g_autofree char *ttyHostPath =3D NULL; =20 for (i =3D 0; i < ctrl->nconsoles; i++) { + g_autofree char *ttyHostPath =3D NULL; + VIR_DEBUG("Opening tty on private %s", ctrl->devptmx); if (lxcCreateTty(ctrl, &ctrl->consoles[i].contFd, @@ -2248,8 +2224,6 @@ virLXCControllerSetupConsoles(virLXCControllerPtr ctr= l, /* Change the owner of tty device to the root user of container */ if (lxcContainerChown(ctrl->def, ttyHostPath) < 0) return -1; - - VIR_FREE(ttyHostPath); } =20 return 0; @@ -2484,8 +2458,8 @@ virLXCControllerRun(virLXCControllerPtr ctrl) VIR_FORCE_CLOSE(containerhandshake[1]); =20 for (i =3D 0; i < ctrl->nconsoles; i++) - VIR_FREE(containerTTYPaths[i]); - VIR_FREE(containerTTYPaths); + g_free(containerTTYPaths[i]); + g_free(containerTTYPaths); =20 virLXCControllerStopInit(ctrl); =20 @@ -2517,9 +2491,9 @@ int main(int argc, char *argv[]) { "help", 0, NULL, 'h' }, { 0, 0, 0, 0 }, }; - int *ttyFDs =3D NULL; + g_autofree int *ttyFDs =3D NULL; size_t nttyFDs =3D 0; - int *passFDs =3D NULL; + g_autofree int *passFDs =3D NULL; size_t npassFDs =3D 0; virLXCControllerPtr ctrl =3D NULL; size_t i; @@ -2760,10 +2734,8 @@ int main(int argc, char *argv[]) virLXCControllerDeleteInterfaces(ctrl); for (i =3D 0; i < nttyFDs; i++) VIR_FORCE_CLOSE(ttyFDs[i]); - VIR_FREE(ttyFDs); for (i =3D 0; i < npassFDs; i++) VIR_FORCE_CLOSE(passFDs[i]); - VIR_FREE(passFDs); =20 virLXCControllerFree(ctrl); =20 diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index 59f803837a..b9c3b4eec3 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -159,7 +159,7 @@ virLXCDomainObjPrivateAlloc(void *opaque G_GNUC_UNUSED) return NULL; =20 if (virLXCDomainObjInitJob(priv) < 0) { - VIR_FREE(priv); + g_free(priv); return NULL; } =20 @@ -174,7 +174,7 @@ virLXCDomainObjPrivateFree(void *data) =20 virCgroupFree(&priv->cgroup); virLXCDomainObjFreeJob(priv); - VIR_FREE(priv); + g_free(priv); } =20 =20 @@ -200,8 +200,8 @@ lxcDomainDefNamespaceFree(void *nsdata) size_t i; lxcDomainDefPtr lxcDef =3D nsdata; for (i =3D 0; i < VIR_LXC_DOMAIN_NAMESPACE_LAST; i++) - VIR_FREE(lxcDef->ns_val[i]); - VIR_FREE(nsdata); + g_free(lxcDef->ns_val[i]); + g_free(nsdata); } =20 static int @@ -209,12 +209,11 @@ lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt, void **data) { lxcDomainDefPtr lxcDef =3D NULL; - xmlNodePtr *nodes =3D NULL; + g_autofree xmlNodePtr *nodes =3D NULL; bool uses_lxc_ns =3D false; xmlNodePtr node; int feature; int n; - char *tmp =3D NULL; size_t i; =20 if (VIR_ALLOC(lxcDef) < 0) @@ -226,6 +225,7 @@ lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt, uses_lxc_ns |=3D n > 0; =20 for (i =3D 0; i < n; i++) { + g_autofree char *tmp =3D NULL; if ((feature =3D virLXCDomainNamespaceTypeFromString( (const char *)nodes[i]->name)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -246,10 +246,8 @@ lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown LXC namespace source '%s'"), tmp); - VIR_FREE(tmp); goto error; } - VIR_FREE(tmp); =20 if (!(lxcDef->ns_val[feature] =3D virXMLPropString(nodes[i], "value"))) { @@ -258,15 +256,13 @@ lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt, goto error; } } - VIR_FREE(nodes); ctxt->node =3D node; if (uses_lxc_ns) *data =3D lxcDef; else - VIR_FREE(lxcDef); + g_free(lxcDef); return 0; error: - VIR_FREE(nodes); lxcDomainDefNamespaceFree(lxcDef); return -1; } @@ -496,7 +492,9 @@ virLXCDomainSetRunlevel(virDomainObjPtr vm, lxcDomainInitctlCallback, &data); cleanup: - VIR_FREE(data.st); - VIR_FREE(data.st_valid); + g_free(data.st); + data.st =3D NULL; + g_free(data.st_valid); + data.st_valid =3D NULL; return ret; } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 3111562568..2c63b0f3a3 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1496,7 +1496,8 @@ static int lxcStateInitialize(bool privileged, return VIR_DRV_STATE_INIT_ERROR; lxc_driver->lockFD =3D -1; if (virMutexInit(&lxc_driver->lock) < 0) { - VIR_FREE(lxc_driver); + g_free(lxc_driver); + lxc_driver =3D NULL; return VIR_DRV_STATE_INIT_ERROR; } =20 @@ -1633,7 +1634,8 @@ static int lxcStateCleanup(void) =20 virObjectUnref(lxc_driver->config); virMutexDestroy(&lxc_driver->lock); - VIR_FREE(lxc_driver); + g_free(lxc_driver); + lxc_driver =3D NULL; =20 return 0; } @@ -2473,7 +2475,8 @@ static int lxcDomainSetAutostart(virDomainPtr dom, { virLXCDriverPtr driver =3D dom->conn->privateData; virDomainObjPtr vm; - char *configFile =3D NULL, *autostartLink =3D NULL; + g_autofree char *configFile =3D NULL; + g_autofree char *autostartLink =3D NULL; int ret =3D -1; virLXCDriverConfigPtr cfg =3D virLXCDriverGetConfig(driver); =20 @@ -2538,8 +2541,6 @@ static int lxcDomainSetAutostart(virDomainPtr dom, virLXCDomainObjEndJob(driver, vm); =20 cleanup: - VIR_FREE(configFile); - VIR_FREE(autostartLink); virDomainObjEndAPI(&vm); virObjectUnref(cfg); return ret; @@ -2551,8 +2552,7 @@ static int lxcFreezeContainer(virDomainObjPtr vm) int check_interval =3D 1; /* In milliseconds */ int exp =3D 10; int waited_time =3D 0; - int ret =3D -1; - char *state =3D NULL; + g_autofree char *state =3D NULL; virLXCDomainObjPrivatePtr priv =3D vm->privateData; =20 while (waited_time < timeout) { @@ -2599,10 +2599,8 @@ static int lxcFreezeContainer(virDomainObjPtr vm) } VIR_DEBUG("Read freezer.state: %s", state); =20 - if (STREQ(state, "FROZEN")) { - ret =3D 0; - goto cleanup; - } + if (STREQ(state, "FROZEN")) + return 0; =20 waited_time +=3D check_interval; /* @@ -2614,7 +2612,6 @@ static int lxcFreezeContainer(virDomainObjPtr vm) * In that case, eager polling will just waste CPU time. */ check_interval *=3D exp; - VIR_FREE(state); } VIR_DEBUG("lxcFreezeContainer timeout"); error: @@ -2624,11 +2621,7 @@ static int lxcFreezeContainer(virDomainObjPtr vm) * This is likely to fall the group back again gracefully. */ virCgroupSetFreezerState(priv->cgroup, "THAWED"); - ret =3D -1; - - cleanup: - VIR_FREE(state); - return ret; + return -1; } =20 static int lxcDomainSuspend(virDomainPtr dom) @@ -3345,7 +3338,7 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver, virDomainDiskDefPtr def =3D dev->data.disk; int ret =3D -1; struct stat sb; - char *file =3D NULL; + g_autofree char *file =3D NULL; int perms; const char *src =3D NULL; =20 @@ -3433,7 +3426,6 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver, cleanup: if (src) virDomainAuditDisk(vm, NULL, def->src, "attach", ret =3D=3D 0); - VIR_FREE(file); return ret; } =20 @@ -3584,7 +3576,7 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDrive= rPtr driver, virLXCDomainObjPrivatePtr priv =3D vm->privateData; virDomainHostdevDefPtr def =3D dev->data.hostdev; int ret =3D -1; - char *src =3D NULL; + g_autofree char *src =3D NULL; struct stat sb; virUSBDevicePtr usb =3D NULL; virDomainHostdevSubsysUSBPtr usbsrc; @@ -3643,7 +3635,6 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDrive= rPtr driver, cleanup: virDomainAuditHostdev(vm, def, "attach", ret =3D=3D 0); virUSBDeviceFree(usb); - VIR_FREE(src); return ret; } =20 @@ -3910,14 +3901,14 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm, { virLXCDomainObjPrivatePtr priv =3D vm->privateData; virDomainDiskDefPtr def =3D NULL; - int idx, ret =3D -1; - char *dst =3D NULL; + int idx; + g_autofree char *dst =3D NULL; const char *src; =20 if (!priv->initpid) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Cannot attach disk until init PID is known")); - goto cleanup; + return -1; } =20 if ((idx =3D virDomainDiskIndexByName(vm->def, @@ -3925,7 +3916,7 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm, false)) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, _("disk %s not found"), dev->data.disk->dst); - goto cleanup; + return -1; } =20 def =3D vm->def->disks[idx]; @@ -3936,12 +3927,12 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm, if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("devices cgroup isn't mounted")); - goto cleanup; + return -1; } =20 if (lxcDomainAttachDeviceUnlink(vm, dst) < 0) { virDomainAuditDisk(vm, def->src, NULL, "detach", false); - goto cleanup; + return -1; } virDomainAuditDisk(vm, def->src, NULL, "detach", true); =20 @@ -3953,11 +3944,7 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm, virDomainDiskRemove(vm->def, idx); virDomainDiskDefFree(def); =20 - ret =3D 0; - - cleanup: - VIR_FREE(dst); - return ret; + return 0; } =20 =20 @@ -4055,7 +4042,7 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr d= river, virLXCDomainObjPrivatePtr priv =3D vm->privateData; virDomainHostdevDefPtr def =3D NULL; int idx, ret =3D -1; - char *dst =3D NULL; + g_autofree char *dst =3D NULL; virUSBDevicePtr usb =3D NULL; virHostdevManagerPtr hostdev_mgr =3D driver->hostdevMgr; virDomainHostdevSubsysUSBPtr usbsrc; @@ -4103,7 +4090,6 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr d= river, =20 cleanup: virUSBDeviceFree(usb); - VIR_FREE(dst); return ret; } =20 @@ -4948,8 +4934,6 @@ lxcDomainGetHostname(virDomainPtr dom, virDomainObjPtr vm =3D NULL; char macaddr[VIR_MAC_STRING_BUFLEN]; g_autoptr(virConnect) conn =3D NULL; - virNetworkDHCPLeasePtr *leases =3D NULL; - int n_leases; size_t i, j; char *hostname =3D NULL; =20 @@ -4973,6 +4957,8 @@ lxcDomainGetHostname(virDomainPtr dom, for (i =3D 0; i < vm->def->nnets; i++) { g_autoptr(virNetwork) network =3D NULL; virDomainNetDefPtr net =3D vm->def->nets[i]; + g_autofree virNetworkDHCPLeasePtr *leases =3D NULL; + int n_leases; =20 if (net->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) continue; @@ -4996,8 +4982,6 @@ lxcDomainGetHostname(virDomainPtr dom, virNetworkDHCPLeaseFree(lease); } =20 - VIR_FREE(leases); - if (hostname) goto endjob; } diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c index e73b4d0690..c4223f4e06 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -326,10 +326,10 @@ int lxcSetupFuse(virLXCFusePtr *f, virDomainDefPtr de= f) *f =3D fuse; return ret; cleanup1: - VIR_FREE(fuse->mountpoint); + g_free(fuse->mountpoint); virMutexDestroy(&fuse->lock); cleanup2: - VIR_FREE(fuse); + g_free(fuse); goto cleanup; } =20 @@ -356,8 +356,8 @@ void lxcFreeFuse(virLXCFusePtr *f) fuse_exit(fuse->fuse); virMutexUnlock(&fuse->lock); =20 - VIR_FREE(fuse->mountpoint); - VIR_FREE(*f); + g_free(fuse->mountpoint); + g_free(*f); } } #else diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c index 479125374b..e0d03f9d4c 100644 --- a/src/lxc/lxc_monitor.c +++ b/src/lxc/lxc_monitor.c @@ -143,7 +143,7 @@ virLXCMonitorPtr virLXCMonitorNew(virDomainObjPtr vm, virLXCMonitorCallbacksPtr cb) { virLXCMonitorPtr mon; - char *sockpath =3D NULL; + g_autofree char *sockpath =3D NULL; =20 if (virLXCMonitorInitialize() < 0) return NULL; @@ -180,14 +180,11 @@ virLXCMonitorPtr virLXCMonitorNew(virDomainObjPtr vm, mon->vm =3D virObjectRef(vm); memcpy(&mon->cb, cb, sizeof(mon->cb)); =20 - cleanup: - VIR_FREE(sockpath); return mon; =20 error: virObjectUnref(mon); - mon =3D NULL; - goto cleanup; + return NULL; } =20 =20 diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 4545d8cde1..622d506398 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -93,11 +93,11 @@ lxcFstabFree(lxcFstabPtr fstab) lxcFstabPtr next =3D NULL; next =3D fstab->next; =20 - VIR_FREE(fstab->src); - VIR_FREE(fstab->dst); - VIR_FREE(fstab->type); - VIR_FREE(fstab->options); - VIR_FREE(fstab); + g_free(fstab->src); + g_free(fstab->dst); + g_free(fstab->type); + g_free(fstab->options); + g_free(fstab); =20 fstab =3D next; } @@ -105,7 +105,7 @@ lxcFstabFree(lxcFstabPtr fstab) =20 static char ** lxcStringSplit(const char *string) { - char *tmp; + g_autofree char *tmp =3D NULL; size_t i; size_t ntokens =3D 0; char **parts; @@ -136,12 +136,10 @@ static char ** lxcStringSplit(const char *string) result[ntokens - 2] =3D g_strdup(parts[i]); } =20 - VIR_FREE(tmp); virStringListFree(parts); return result; =20 error: - VIR_FREE(tmp); virStringListFree(parts); virStringListFree(result); return NULL; @@ -257,7 +255,7 @@ static int lxcAddFstabLine(virDomainDefPtr def, lxcFstabPtr fstab) { const char *src =3D NULL; - char *dst =3D NULL; + g_autofree char *dst =3D NULL; char **options =3D virStringSplit(fstab->options, ",", 0); bool readonly; int type =3D VIR_DOMAIN_FS_TYPE_MOUNT; @@ -313,7 +311,6 @@ lxcAddFstabLine(virDomainDefPtr def, lxcFstabPtr fstab) ret =3D 1; =20 cleanup: - VIR_FREE(dst); virStringListFree(options); return ret; } @@ -444,8 +441,8 @@ lxcAddNetworkRouteDefinition(const char *address, size_t *nroutes) { virNetDevIPRoutePtr route =3D NULL; - char *familyStr =3D NULL; - char *zero =3D NULL; + g_autofree char *familyStr =3D NULL; + g_autofree char *zero =3D NULL; =20 zero =3D g_strdup(family =3D=3D AF_INET ? VIR_SOCKET_ADDR_IPV4_ALL : V= IR_SOCKET_ADDR_IPV6_ALL); =20 @@ -459,14 +456,9 @@ lxcAddNetworkRouteDefinition(const char *address, if (VIR_APPEND_ELEMENT(*routes, *nroutes, route) < 0) goto error; =20 - VIR_FREE(familyStr); - VIR_FREE(zero); - return 0; =20 error: - VIR_FREE(familyStr); - VIR_FREE(zero); virNetDevIPRouteFree(route); return -1; } @@ -499,7 +491,7 @@ lxcAddNetworkDefinition(virDomainDefPtr def, lxcNetwork= ParseData *data) /* This still requires the user to manually setup the vlan interfa= ce * on the host */ if (isVlan && data->vlanid) { - VIR_FREE(hostdev->source.caps.u.net.ifname); + g_free(hostdev->source.caps.u.net.ifname); hostdev->source.caps.u.net.ifname =3D g_strdup_printf("%s.%s", data->link, data->vlan= id); @@ -553,8 +545,9 @@ lxcAddNetworkDefinition(virDomainDefPtr def, lxcNetwork= ParseData *data) =20 error: for (i =3D 0; i < data->nips; i++) - VIR_FREE(data->ips[i]); - VIR_FREE(data->ips); + g_free(data->ips[i]); + g_free(data->ips); + data->ips =3D NULL; virDomainNetDefFree(net); virDomainHostdevDefFree(hostdev); return -1; @@ -568,7 +561,7 @@ lxcNetworkParseDataIPs(const char *name, { int family =3D AF_INET; char **ipparts =3D NULL; - virNetDevIPAddrPtr ip =3D NULL; + g_autofree virNetDevIPAddrPtr ip =3D NULL; =20 if (VIR_ALLOC(ip) < 0) return -1; @@ -585,16 +578,13 @@ lxcNetworkParseDataIPs(const char *name, _("Invalid CIDR address: '%s'"), value->str); =20 virStringListFree(ipparts); - VIR_FREE(ip); return -1; } =20 virStringListFree(ipparts); =20 - if (VIR_APPEND_ELEMENT(parseData->ips, parseData->nips, ip) < 0) { - VIR_FREE(ip); + if (VIR_APPEND_ELEMENT(parseData->ips, parseData->nips, ip) < 0) return -1; - } =20 return 0; } @@ -792,16 +782,18 @@ lxcConvertNetworkSettings(virDomainDefPtr def, virCon= fPtr properties) =20 cleanup: for (i =3D 0; i < networks.ndata; i++) - VIR_FREE(networks.parseData[i]); - VIR_FREE(networks.parseData); + g_free(networks.parseData[i]); + g_free(networks.parseData); + networks.parseData =3D NULL; return ret; =20 error: for (i =3D 0; i < networks.ndata; i++) { lxcNetworkParseDataPtr data =3D networks.parseData[i]; for (j =3D 0; j < data->nips; j++) - VIR_FREE(data->ips[j]); - VIR_FREE(data->ips); + g_free(data->ips[j]); + g_free(data->ips); + data->ips =3D NULL; } goto cleanup; } @@ -905,7 +897,8 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr propertie= s) size =3D size / 1024; virDomainDefSetMemoryTotal(def, size); def->mem.hard_limit =3D virMemoryLimitTruncate(size); - VIR_FREE(value); + g_free(value); + value =3D NULL; } =20 if (virConfGetValueString(properties, @@ -914,7 +907,8 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr propertie= s) if (lxcConvertSize(value, &size) < 0) return -1; def->mem.soft_limit =3D virMemoryLimitTruncate(size / 1024); - VIR_FREE(value); + g_free(value); + value =3D NULL; } =20 if (virConfGetValueString(properties, @@ -937,14 +931,16 @@ lxcSetCpuTune(virDomainDefPtr def, virConfPtr propert= ies) if (virStrToLong_ull(value, NULL, 10, &def->cputune.shares) < 0) goto error; def->cputune.sharesSpecified =3D true; - VIR_FREE(value); + g_free(value); + value =3D NULL; } =20 if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_quota_us", &value) > 0) { if (virStrToLong_ll(value, NULL, 10, &def->cputune.quota) < 0) goto error; - VIR_FREE(value); + g_free(value); + value =3D NULL; } =20 if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_period_us", @@ -972,7 +968,8 @@ lxcSetCpusetTune(virDomainDefPtr def, virConfPtr proper= ties) if (virBitmapParse(value, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) <= 0) return -1; def->placement_mode =3D VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC; - VIR_FREE(value); + g_free(value); + value =3D NULL; } =20 if (virConfGetValueString(properties, "lxc.cgroup.cpuset.mems", @@ -1001,7 +998,7 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfVa= luePtr value, void *data) virBlkioDevicePtr device =3D NULL; virDomainDefPtr def =3D data; size_t i =3D 0; - char *path =3D NULL; + g_autofree char *path =3D NULL; int ret =3D -1; =20 if (!STRPREFIX(name, "lxc.cgroup.blkio.") || @@ -1077,8 +1074,6 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfV= aluePtr value, void *data) =20 cleanup: virStringListFree(parts); - VIR_FREE(path); - return ret; } =20 @@ -1172,7 +1167,8 @@ lxcParseConfigString(const char *config, else if (arch =3D=3D VIR_ARCH_NONE && STREQ(value, "amd64")) arch =3D VIR_ARCH_X86_64; vmdef->os.arch =3D arch; - VIR_FREE(value); + g_free(value); + value =3D NULL; } =20 vmdef->os.init =3D g_strdup("/sbin/init"); diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 5199f3806e..998754062c 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -135,14 +135,13 @@ static void lxcProcessRemoveDomainStatus(virLXCDriverConfigPtr cfg, virDomainObjPtr vm) { - char *file =3D NULL; - - file =3D g_strdup_printf("%s/%s.xml", cfg->stateDir, vm->def->name); + g_autofree char *file =3D g_strdup_printf("%s/%s.xml", + cfg->stateDir, + vm->def->name); =20 if (unlink(file) < 0 && errno !=3D ENOENT && errno !=3D ENOTDIR) VIR_WARN("Failed to remove domain XML for %s: %s", vm->def->name, g_strerror(errno)); - VIR_FREE(file); } =20 =20 @@ -170,13 +169,12 @@ static void virLXCProcessCleanup(virLXCDriverPtr driv= er, =20 /* now that we know it's stopped call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml =3D virDomainDefFormat(vm->def, driver->xmlopt, 0); + g_autofree char *xml =3D virDomainDefFormat(vm->def, driver->xmlop= t, 0); =20 /* we can't stop the operation even if the script raised an error = */ virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, VIR_HOOK_LXC_OP_STOPPED, VIR_HOOK_SUBOP_END, NULL, xml, NULL); - VIR_FREE(xml); } =20 virSecurityManagerRestoreAllLabel(driver->securityManager, @@ -185,9 +183,12 @@ static void virLXCProcessCleanup(virLXCDriverPtr drive= r, /* Clear out dynamically assigned labels */ if (vm->def->nseclabels && vm->def->seclabels[0]->type =3D=3D VIR_DOMAIN_SECLABEL_DYNAMIC) { - VIR_FREE(vm->def->seclabels[0]->model); - VIR_FREE(vm->def->seclabels[0]->label); - VIR_FREE(vm->def->seclabels[0]->imagelabel); + g_free(vm->def->seclabels[0]->model); + g_free(vm->def->seclabels[0]->label); + g_free(vm->def->seclabels[0]->imagelabel); + vm->def->seclabels[0]->model =3D NULL; + vm->def->seclabels[0]->label =3D NULL; + vm->def->seclabels[0]->imagelabel =3D NULL; } =20 /* Stop autodestroy in case guest is restarted */ @@ -243,17 +244,17 @@ static void virLXCProcessCleanup(virLXCDriverPtr driv= er, * the bug we are working around here. */ virCgroupTerminateMachine(priv->machineName); - VIR_FREE(priv->machineName); + g_free(priv->machineName); + priv->machineName =3D NULL; =20 /* The "release" hook cleans up additional resources */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml =3D virDomainDefFormat(vm->def, driver->xmlopt, 0); + g_autofree char *xml =3D virDomainDefFormat(vm->def, driver->xmlop= t, 0); =20 /* we can't stop the operation even if the script raised an error = */ virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, VIR_HOOK_LXC_OP_RELEASE, VIR_HOOK_SUBOP_END, NULL, xml, NULL); - VIR_FREE(xml); } =20 virDomainObjRemoveTransientDef(vm); @@ -442,12 +443,9 @@ static int virLXCProcessSetupNamespaceName(virLXCDrive= rPtr driver, =20 static int virLXCProcessSetupNamespacePID(int ns_type, const char *name) { - int fd; - char *path; - - path =3D g_strdup_printf("/proc/%s/ns/%s", name, nsInfoLocal[ns_type]); - fd =3D open(path, O_RDONLY); - VIR_FREE(path); + g_autofree char *path =3D g_strdup_printf("/proc/%s/ns/%s", + name, nsInfoLocal[ns_type]); + int fd =3D open(path, O_RDONLY); if (fd < 0) { virReportSystemError(errno, _("failed to open ns %s"), @@ -460,7 +458,7 @@ static int virLXCProcessSetupNamespacePID(int ns_type, = const char *name) =20 static int virLXCProcessSetupNamespaceNet(int ns_type, const char *name) { - char *path; + g_autofree char *path =3D NULL; int fd; if (ns_type !=3D VIR_LXC_DOMAIN_NAMESPACE_SHARENET) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -471,7 +469,6 @@ static int virLXCProcessSetupNamespaceNet(int ns_type, = const char *name) =20 path =3D g_strdup_printf("%s/netns/%s", RUNSTATEDIR, name); fd =3D open(path, O_RDONLY); - VIR_FREE(path); if (fd < 0) { virReportSystemError(errno, _("failed to open netns %s"), name); @@ -669,7 +666,8 @@ virLXCProcessCleanInterfaces(virDomainDefPtr def) size_t i; =20 for (i =3D 0; i < def->nnets; i++) { - VIR_FREE(def->nets[i]->ifname_guest_actual); + g_free(def->nets[i]->ifname_guest_actual); + def->nets[i]->ifname_guest_actual =3D NULL; VIR_DEBUG("Cleared net names: %s", def->nets[i]->ifname_guest); } } @@ -757,24 +755,20 @@ virLXCProcessGetNsInode(pid_t pid, const char *nsname, ino_t *inode) { - char *path =3D NULL; + g_autofree char *path =3D NULL; struct stat sb; - int ret =3D -1; =20 path =3D g_strdup_printf("/proc/%lld/ns/%s", (long long)pid, nsname); =20 if (stat(path, &sb) < 0) { virReportSystemError(errno, _("Unable to stat %s"), path); - goto cleanup; + return -1; } =20 *inode =3D sb.st_ino; - ret =3D 0; =20 - cleanup: - VIR_FREE(path); - return ret; + return 0; } =20 =20 @@ -929,8 +923,8 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver, const char *pidfile) { size_t i; - char *filterstr; - char *outputstr; + g_autofree char *filterstr =3D NULL; + g_autofree char *outputstr =3D NULL; virCommandPtr cmd; virLXCDriverConfigPtr cfg =3D virLXCDriverGetConfig(driver); =20 @@ -950,7 +944,6 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver, } =20 virCommandAddEnvPair(cmd, "LIBVIRT_LOG_FILTERS", filterstr); - VIR_FREE(filterstr); } =20 if (cfg->log_libvirtd) { @@ -962,7 +955,6 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver, } =20 virCommandAddEnvPair(cmd, "LIBVIRT_LOG_OUTPUTS", outputstr); - VIR_FREE(outputstr); } } else { virCommandAddEnvFormat(cmd, @@ -985,12 +977,11 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr drive= r, =20 for (i =3D 0; i < VIR_LXC_DOMAIN_NAMESPACE_LAST; i++) { if (nsInheritFDs[i] > 0) { - char *tmp =3D NULL; - tmp =3D g_strdup_printf("--share-%s", nsInfoLocal[i]); + g_autofree char *tmp =3D g_strdup_printf("--share-%s", + nsInfoLocal[i]); virCommandAddArg(cmd, tmp); virCommandAddArgFormat(cmd, "%d", nsInheritFDs[i]); virCommandPassFD(cmd, nsInheritFDs[i], 0); - VIR_FREE(tmp); } } =20 @@ -1188,15 +1179,15 @@ int virLXCProcessStart(virConnectPtr conn, { int rc =3D -1, r; size_t nttyFDs =3D 0; - int *ttyFDs =3D NULL; + g_autofree int *ttyFDs =3D NULL; size_t i; - char *logfile =3D NULL; + g_autofree char *logfile =3D NULL; int logfd =3D -1; VIR_AUTOSTRINGLIST veths =3D NULL; int handshakefds[2] =3D { -1, -1 }; off_t pos =3D -1; char ebuf[1024]; - char *timestamp; + g_autofree char *timestamp =3D NULL; int nsInheritFDs[VIR_LXC_DOMAIN_NAMESPACE_LAST]; virCommandPtr cmd =3D NULL; virLXCDomainObjPrivatePtr priv =3D vm->privateData; @@ -1205,7 +1196,7 @@ int virLXCProcessStart(virConnectPtr conn, virLXCDriverConfigPtr cfg =3D virLXCDriverGetConfig(driver); virCgroupPtr selfcgroup; int status; - char *pidfile =3D NULL; + g_autofree char *pidfile =3D NULL; =20 if (virCgroupNewSelf(&selfcgroup) < 0) return -1; @@ -1283,18 +1274,14 @@ int virLXCProcessStart(virConnectPtr conn, =20 /* Run an early hook to set-up missing devices */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml =3D virDomainDefFormat(vm->def, driver->xmlopt, 0); - int hookret; - - hookret =3D virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, - VIR_HOOK_LXC_OP_PREPARE, VIR_HOOK_SUBOP_BEGI= N, - NULL, xml, NULL); - VIR_FREE(xml); + g_autofree char *xml =3D virDomainDefFormat(vm->def, driver->xmlop= t, 0); =20 /* * If the script raised an error abort the launch */ - if (hookret < 0) + if (virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, + VIR_HOOK_LXC_OP_PREPARE, VIR_HOOK_SUBOP_BEGIN, + NULL, xml, NULL) < 0) goto cleanup; } =20 @@ -1348,10 +1335,10 @@ int virLXCProcessStart(virConnectPtr conn, goto cleanup; } =20 - VIR_FREE(vm->def->consoles[i]->source->data.file.path); + g_free(vm->def->consoles[i]->source->data.file.path); vm->def->consoles[i]->source->data.file.path =3D ttyPath; =20 - VIR_FREE(vm->def->consoles[i]->info.alias); + g_free(vm->def->consoles[i]->info.alias); vm->def->consoles[i]->info.alias =3D g_strdup_printf("console%zu",= i); } =20 @@ -1388,18 +1375,14 @@ int virLXCProcessStart(virConnectPtr conn, =20 /* now that we know it is about to start call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml =3D virDomainDefFormat(vm->def, driver->xmlopt, 0); - int hookret; - - hookret =3D virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, - VIR_HOOK_LXC_OP_START, VIR_HOOK_SUBOP_BEGIN, - NULL, xml, NULL); - VIR_FREE(xml); + g_autofree char *xml =3D virDomainDefFormat(vm->def, driver->xmlop= t, 0); =20 /* * If the script raised an error abort the launch */ - if (hookret < 0) + if (virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, + VIR_HOOK_LXC_OP_START, VIR_HOOK_SUBOP_BEGIN, + NULL, xml, NULL) < 0) goto cleanup; } =20 @@ -1411,7 +1394,6 @@ int virLXCProcessStart(virConnectPtr conn, VIR_WARN("Unable to write timestamp to logfile: %s", g_strerror(errno)); } - VIR_FREE(timestamp); =20 /* Log generated command line */ virCommandWriteArgLog(cmd, logfd); @@ -1530,18 +1512,14 @@ int virLXCProcessStart(virConnectPtr conn, =20 /* finally we can call the 'started' hook script if any */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml =3D virDomainDefFormat(vm->def, driver->xmlopt, 0); - int hookret; - - hookret =3D virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, - VIR_HOOK_LXC_OP_STARTED, VIR_HOOK_SUBOP_BEGI= N, - NULL, xml, NULL); - VIR_FREE(xml); + g_autofree char *xml =3D virDomainDefFormat(vm->def, driver->xmlop= t, 0); =20 /* * If the script raised an error abort the launch */ - if (hookret < 0) + if (virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, + VIR_HOOK_LXC_OP_STARTED, VIR_HOOK_SUBOP_BEGIN, + NULL, xml, NULL) < 0) goto cleanup; } =20 @@ -1559,11 +1537,8 @@ int virLXCProcessStart(virConnectPtr conn, virCommandFree(cmd); for (i =3D 0; i < nttyFDs; i++) VIR_FORCE_CLOSE(ttyFDs[i]); - VIR_FREE(ttyFDs); VIR_FORCE_CLOSE(handshakefds[0]); VIR_FORCE_CLOSE(handshakefds[1]); - VIR_FREE(pidfile); - VIR_FREE(logfile); virObjectUnref(cfg); virObjectUnref(caps); =20 @@ -1710,15 +1685,12 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm, =20 /* now that we know it's reconnected call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { - char *xml =3D virDomainDefFormat(vm->def, driver->xmlopt, 0); - int hookret; + g_autofree char *xml =3D virDomainDefFormat(vm->def, driver->x= mlopt, 0); =20 /* we can't stop the operation even if the script raised an er= ror */ - hookret =3D virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, - VIR_HOOK_LXC_OP_RECONNECT, VIR_HOOK_SUBO= P_BEGIN, - NULL, xml, NULL); - VIR_FREE(xml); - if (hookret < 0) + if (virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name, + VIR_HOOK_LXC_OP_RECONNECT, VIR_HOOK_SUBOP_BEGI= N, + NULL, xml, NULL) < 0) goto error; } =20 --=20 2.24.1 From nobody Fri Apr 26 15:33:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1589386984; cv=none; d=zohomail.com; s=zohoarc; b=me6NjJTxWHM4NIf52PBOa4r7SzsR2T880LIivzaydGwS1QxGeFCKirXPIub8Ncjh5oYn29rzcC2GMC+8AJW57TrmUl7QKdeQzYQ0XDYmGkurHz6gpggG0cRx8Cj7boxnPnmldy68pPHm9EvYXQEcmb3YJjQ1Cn84CZWvEjqe/D8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589386984; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uEKVrKswg7aVGB5KT8tGty6RorpV7iA6sJHtOUBjaQw=; b=UJswIs8EE1fNRMqYnaEvDY6Vml8LVgwze/sYxdEf/gcjmceFNvuQTIFXOKhMvNGVGbfbWvfPDiYmTx9eHFV+TiukQPKo7uGW/E89mMLwxjkWLl/BjAdN1w8vSuUOHEbdbz7iKgDVmXceHYNpbgImbFijYazV8pXeNkz2QjoN9Qg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1589386984879283.55760006788785; Wed, 13 May 2020 09:23:04 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-272-pHXV1dmCO4KApSDIwmeX-g-1; Wed, 13 May 2020 12:23:00 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8210F18FE866; Wed, 13 May 2020 16:22:54 +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 62A5410013BD; Wed, 13 May 2020 16:22: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 314621809554; Wed, 13 May 2020 16:22:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 04DGMlvi006724 for ; Wed, 13 May 2020 12:22:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id D8EFC100239A; Wed, 13 May 2020 16:22:47 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (unknown [10.33.8.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4555210013BD; Wed, 13 May 2020 16:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589386983; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=uEKVrKswg7aVGB5KT8tGty6RorpV7iA6sJHtOUBjaQw=; b=JI8ffa0YYEthu8L0l+29i1KT1QULn0CAAOIDa64FOlMfjXjNfBTo7AdkSYUXIpzP4IlL5j WhDlUeda7+W2aRW5FgLA/NJycDK8uJHkCIAYFWlXL0NfgoQIU1YPxMk4dSQiJo+GtBPo7e vTOwNFSMyg1mlnsTEtnWb5CSqgYV2ic= X-MC-Unique: pHXV1dmCO4KApSDIwmeX-g-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/2] lxc: replace VIR_ALLOC/REALLOC with g_new0/renew Date: Wed, 13 May 2020 17:22:41 +0100 Message-Id: <20200513162241.3929790-3-berrange@redhat.com> In-Reply-To: <20200513162241.3929790-1-berrange@redhat.com> References: <20200513162241.3929790-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com 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: , 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- src/lxc/lxc_cgroup.c | 1 - src/lxc/lxc_conf.c | 4 +--- src/lxc/lxc_container.c | 6 ++---- src/lxc/lxc_controller.c | 22 ++++++---------------- src/lxc/lxc_domain.c | 16 ++++------------ src/lxc/lxc_driver.c | 29 ++++++++++++++++------------- src/lxc/lxc_fuse.c | 6 +----- src/lxc/lxc_fuse.h | 1 + src/lxc/lxc_hostdev.c | 1 - src/lxc/lxc_monitor.c | 2 -- src/lxc/lxc_native.c | 11 ++++------- src/lxc/lxc_process.c | 11 +++-------- 12 files changed, 38 insertions(+), 72 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 4ae34925e6..e71f37d2b1 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -27,7 +27,6 @@ #include "virfile.h" #include "virerror.h" #include "virlog.h" -#include "viralloc.h" #include "virstring.h" #include "virsystemd.h" #include "virutil.h" diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 43e9b70651..13da6c4586 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -29,7 +29,6 @@ #include "lxc_domain.h" #include "virerror.h" #include "virconf.h" -#include "viralloc.h" #include "virlog.h" #include "viruuid.h" #include "configmake.h" @@ -145,8 +144,7 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver) VIR_DOMAIN_VIRT_LXC); type =3D virDomainVirtTypeToString(VIR_DOMAIN_VIRT_LXC); /* Allocate the primary security driver for LXC. */ - if (VIR_ALLOC(caps->host.secModels) < 0) - goto error; + caps->host.secModels =3D g_new0(virCapsHostSecModel, 1); caps->host.nsecModels =3D 1; caps->host.secModels[0].model =3D g_strdup(model); caps->host.secModels[0].doi =3D g_strdup(doi); diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index bd78fa7af6..77df49ea75 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -156,8 +156,7 @@ int lxcContainerHasReboot(void) } cmd =3D v ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF; =20 - if (VIR_ALLOC_N(stack, stacksize) < 0) - return -1; + stack =3D g_new0(char, stacksize); =20 childStack =3D stack + stacksize; =20 @@ -2322,8 +2321,7 @@ int lxcContainerStart(virDomainDefPtr def, }; =20 /* allocate a stack for the container */ - if (VIR_ALLOC_N(stack, stacksize) < 0) - return -1; + stack =3D g_new0(char, stacksize); =20 stacktop =3D stack + stacksize; =20 diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 0438d72538..4672920574 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -189,13 +189,10 @@ virLXCControllerDriverFree(virLXCDriverPtr driver) =20 static virLXCControllerPtr virLXCControllerNew(const char *name) { - virLXCControllerPtr ctrl =3D NULL; + virLXCControllerPtr ctrl =3D g_new0(virLXCController, 1); virLXCDriverPtr driver =3D NULL; g_autofree char *configFile =3D NULL; =20 - if (VIR_ALLOC(ctrl) < 0) - goto error; - ctrl->timerShutdown =3D -1; ctrl->firstClient =3D true; =20 @@ -2333,12 +2330,9 @@ virLXCControllerRun(virLXCControllerPtr ctrl) int rc =3D -1; int control[2] =3D { -1, -1}; int containerhandshake[2] =3D { -1, -1 }; - char **containerTTYPaths =3D NULL; + char **containerTTYPaths =3D g_new0(char *, ctrl->nconsoles); size_t i; =20 - if (VIR_ALLOC_N(containerTTYPaths, ctrl->nconsoles) < 0) - goto cleanup; - if (socketpair(PF_UNIX, SOCK_STREAM, 0, control) < 0) { virReportSystemError(errno, "%s", _("sockpair failed")); @@ -2530,14 +2524,12 @@ int main(int argc, char *argv[]) break; =20 case 'v': - if (VIR_REALLOC_N(veths, nveths+1) < 0) - goto cleanup; + veths =3D g_renew(char *, veths, nveths+1); veths[nveths++] =3D g_strdup(optarg); break; =20 case 'c': - if (VIR_REALLOC_N(ttyFDs, nttyFDs + 1) < 0) - goto cleanup; + ttyFDs =3D g_renew(int, ttyFDs, nttyFDs + 1); if (virStrToLong_i(optarg, NULL, 10, &ttyFDs[nttyFDs++]) < 0) { fprintf(stderr, "malformed --console argument '%s'", optar= g); goto cleanup; @@ -2545,8 +2537,7 @@ int main(int argc, char *argv[]) break; =20 case 'p': - if (VIR_REALLOC_N(passFDs, npassFDs + 1) < 0) - goto cleanup; + passFDs =3D g_renew(int, passFDs, npassFDs + 1); if (virStrToLong_i(optarg, NULL, 10, &passFDs[npassFDs++]) < 0= ) { fprintf(stderr, "malformed --passfd argument '%s'", optarg= ); goto cleanup; @@ -2661,8 +2652,7 @@ int main(int argc, char *argv[]) if (ns_fd[i] !=3D -1) { if (!ctrl->nsFDs) {/*allocate only once */ size_t j =3D 0; - if (VIR_ALLOC_N(ctrl->nsFDs, VIR_LXC_DOMAIN_NAMESPACE_LAST= ) < 0) - goto cleanup; + ctrl->nsFDs =3D g_new0(int, VIR_LXC_DOMAIN_NAMESPACE_LAST); for (j =3D 0; j < VIR_LXC_DOMAIN_NAMESPACE_LAST; j++) ctrl->nsFDs[j] =3D -1; } diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index b9c3b4eec3..bf82844fd2 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -23,7 +23,6 @@ =20 #include "lxc_domain.h" =20 -#include "viralloc.h" #include "virlog.h" #include "virerror.h" #include "virstring.h" @@ -153,10 +152,7 @@ virLXCDomainObjEndJob(virLXCDriverPtr driver G_GNUC_UN= USED, static void * virLXCDomainObjPrivateAlloc(void *opaque G_GNUC_UNUSED) { - virLXCDomainObjPrivatePtr priv; - - if (VIR_ALLOC(priv) < 0) - return NULL; + virLXCDomainObjPrivatePtr priv =3D g_new0(virLXCDomainObjPrivate, 1); =20 if (virLXCDomainObjInitJob(priv) < 0) { g_free(priv); @@ -208,7 +204,7 @@ static int lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt, void **data) { - lxcDomainDefPtr lxcDef =3D NULL; + lxcDomainDefPtr lxcDef =3D g_new0(lxcDomainDef, 1); g_autofree xmlNodePtr *nodes =3D NULL; bool uses_lxc_ns =3D false; xmlNodePtr node; @@ -216,9 +212,6 @@ lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt, int n; size_t i; =20 - if (VIR_ALLOC(lxcDef) < 0) - return -1; - node =3D ctxt->node; if ((n =3D virXPathNodeSet("./lxc:namespace/*", ctxt, &nodes)) < 0) goto error; @@ -470,9 +463,8 @@ virLXCDomainSetRunlevel(virDomainObjPtr vm, for (nfifos =3D 0; virInitctlFifos[nfifos]; nfifos++) ; =20 - if (VIR_ALLOC_N(data.st, nfifos) < 0 || - VIR_ALLOC_N(data.st_valid, nfifos) < 0) - goto cleanup; + data.st =3D g_new0(struct stat, nfifos); + data.st_valid =3D g_new0(bool, nfifos); =20 for (i =3D 0; virInitctlFifos[i]; i++) { const char *fifo =3D virInitctlFifos[i]; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 2c63b0f3a3..46a182be45 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -44,7 +44,6 @@ #include "lxc_driver.h" #include "lxc_native.h" #include "lxc_process.h" -#include "viralloc.h" #include "virnetdevbridge.h" #include "virnetdevveth.h" #include "virnetdevopenvswitch.h" @@ -1492,8 +1491,7 @@ static int lxcStateInitialize(bool privileged, return VIR_DRV_STATE_INIT_SKIPPED; } =20 - if (VIR_ALLOC(lxc_driver) < 0) - return VIR_DRV_STATE_INIT_ERROR; + lxc_driver =3D g_new0(virLXCDriver, 1); lxc_driver->lockFD =3D -1; if (virMutexInit(&lxc_driver->lock) < 0) { g_free(lxc_driver); @@ -3398,8 +3396,9 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver, perms) < 0) goto cleanup; =20 - if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks + 1) < 0) - goto cleanup; + vm->def->disks =3D g_renew(virDomainDiskDefPtr, + vm->def->disks, + vm->def->ndisks + 1); =20 file =3D g_strdup_printf("/dev/%s", def->dst); =20 @@ -3451,8 +3450,9 @@ lxcDomainAttachDeviceNetLive(virLXCDriverPtr driver, return -1; =20 /* preallocate new slot for device */ - if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets+1) < 0) - return -1; + vm->def->nets =3D g_renew(virDomainNetDefPtr, + vm->def->nets, + vm->def->nnets + 1); =20 /* If appropriate, grab a physical device from the configured * network's pool of devices, or resolve bridge device name @@ -3606,8 +3606,9 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDrive= rPtr driver, goto cleanup; } =20 - if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0) - goto cleanup; + vm->def->hostdevs =3D g_renew(virDomainHostdevDefPtr, + vm->def->hostdevs, + vm->def->nhostdevs + 1); =20 if (virUSBDeviceFileIterate(usb, virLXCSetupHostUSBDeviceCgroup, @@ -3675,8 +3676,9 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverP= tr driver, goto cleanup; } =20 - if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) - goto cleanup; + vm->def->hostdevs =3D g_renew(virDomainHostdevDefPtr, + vm->def->hostdevs, + vm->def->nhostdevs + 1); =20 if (virCgroupAllowDevice(priv->cgroup, 'b', @@ -3754,8 +3756,9 @@ lxcDomainAttachDeviceHostdevMiscLive(virLXCDriverPtr = driver, VIR_CGROUP_DEVICE_RWM) < 0) goto cleanup; =20 - if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) - goto cleanup; + vm->def->hostdevs =3D g_renew(virDomainHostdevDefPtr, + vm->def->hostdevs, + vm->def->nhostdevs + 1); =20 if (lxcDomainAttachDeviceMknod(driver, 0700 | S_IFBLK, diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c index c4223f4e06..146629f67e 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -31,7 +31,6 @@ #include "virfile.h" #include "virbuffer.h" #include "virstring.h" -#include "viralloc.h" #include "virutil.h" =20 #define VIR_FROM_THIS VIR_FROM_LXC @@ -284,10 +283,7 @@ int lxcSetupFuse(virLXCFusePtr *f, virDomainDefPtr def) { int ret =3D -1; struct fuse_args args =3D FUSE_ARGS_INIT(0, NULL); - virLXCFusePtr fuse =3D NULL; - - if (VIR_ALLOC(fuse) < 0) - goto cleanup; + virLXCFusePtr fuse =3D g_new0(virLXCFuse, 1); =20 fuse->def =3D def; =20 diff --git a/src/lxc/lxc_fuse.h b/src/lxc/lxc_fuse.h index e9cfd9a20a..6bba5669a8 100644 --- a/src/lxc/lxc_fuse.h +++ b/src/lxc/lxc_fuse.h @@ -50,6 +50,7 @@ struct virLXCFuse { struct fuse_chan *ch; virMutex lock; }; +typedef struct virLXCFuse virLXCFuse; typedef struct virLXCFuse *virLXCFusePtr; =20 int lxcSetupFuse(virLXCFusePtr *f, virDomainDefPtr def); diff --git a/src/lxc/lxc_hostdev.c b/src/lxc/lxc_hostdev.c index 6dbed9b9a4..609fbe5c87 100644 --- a/src/lxc/lxc_hostdev.c +++ b/src/lxc/lxc_hostdev.c @@ -22,7 +22,6 @@ #include =20 #include "lxc_hostdev.h" -#include "viralloc.h" #include "virlog.h" #include "virerror.h" #include "virhostdev.h" diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c index e0d03f9d4c..96c325af49 100644 --- a/src/lxc/lxc_monitor.c +++ b/src/lxc/lxc_monitor.c @@ -24,8 +24,6 @@ #include "lxc_conf.h" #include "lxc_monitor_dispatch.h" =20 -#include "viralloc.h" - #include "virerror.h" #include "virlog.h" #include "virthread.h" diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 622d506398..9e879e438a 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -151,9 +151,10 @@ lxcParseFstabLine(char *fstabLine) lxcFstabPtr fstab =3D NULL; char **parts; =20 - if (!fstabLine || VIR_ALLOC(fstab) < 0) + if (!fstabLine) return NULL; =20 + fstab =3D g_new0(lxcFstab, 1); if (!(parts =3D lxcStringSplit(fstabLine))) goto error; =20 @@ -561,10 +562,7 @@ lxcNetworkParseDataIPs(const char *name, { int family =3D AF_INET; char **ipparts =3D NULL; - g_autofree virNetDevIPAddrPtr ip =3D NULL; - - if (VIR_ALLOC(ip) < 0) - return -1; + g_autofree virNetDevIPAddrPtr ip =3D g_new0(virNetDevIPAddr, 1); =20 if (STREQ(name, "ipv6") || STREQ(name, "ipv6.address")) family =3D AF_INET6; @@ -820,8 +818,7 @@ lxcCreateConsoles(virDomainDefPtr def, virConfPtr prope= rties) return -1; } =20 - if (VIR_ALLOC_N(def->consoles, nbttys) < 0) - return -1; + def->consoles =3D g_new0(virDomainChrDefPtr, nbttys); =20 def->nconsoles =3D nbttys; for (i =3D 0; i < nbttys; i++) { diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 998754062c..f3d57875ad 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -550,8 +550,7 @@ virLXCProcessSetupInterfaces(virLXCDriverPtr driver, virConnectPtr netconn =3D NULL; virErrorPtr save_err =3D NULL; =20 - if (VIR_ALLOC_N(*veths, def->nnets + 1) < 0) - return -1; + *veths =3D g_new0(char *, def->nnets + 1); =20 for (i =3D 0; i < def->nnets; i++) { char *veth =3D NULL; @@ -1246,10 +1245,7 @@ int virLXCProcessStart(virConnectPtr conn, } =20 if (!vm->def->resource) { - virDomainResourceDefPtr res; - - if (VIR_ALLOC(res) < 0) - goto cleanup; + virDomainResourceDefPtr res =3D g_new0(virDomainResourceDef, 1); =20 res->partition =3D g_strdup("/machine"); =20 @@ -1298,8 +1294,7 @@ int virLXCProcessStart(virConnectPtr conn, * and forward I/O between them. */ nttyFDs =3D vm->def->nconsoles; - if (VIR_ALLOC_N(ttyFDs, nttyFDs) < 0) - goto cleanup; + ttyFDs =3D g_new0(int, nttyFDs); for (i =3D 0; i < vm->def->nconsoles; i++) ttyFDs[i] =3D -1; =20 --=20 2.24.1