From nobody Wed May 1 20:02:57 2024 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.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1497359399133419.8353505967734; Tue, 13 Jun 2017 06:09:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5791EE3DE4; Tue, 13 Jun 2017 13:09:56 +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 268058E94C; Tue, 13 Jun 2017 13:09:56 +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 5ACCF1841C4F; Tue, 13 Jun 2017 13:09:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5DD9sjJ016750 for ; Tue, 13 Jun 2017 09:09:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1D9478BA29; Tue, 13 Jun 2017 13:09:54 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D7EC8CDEB; Tue, 13 Jun 2017 13:09:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5791EE3DE4 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5791EE3DE4 From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 13 Jun 2017 15:09:47 +0200 Message-Id: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: eskultet@redhat.com Subject: [libvirt] [PATCH] daemonUnixSocketPaths: Unify exit paths 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 13 Jun 2017 13:09:57 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Right now, there is a lot of exit points from the function. Depending on their position they need to copy the same free calls. This goes against our style where we usually have just one exit point from the function which also does the necessary free. Signed-off-by: Michal Privoznik --- daemon/libvirtd.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index d17a694c9..db239f0d4 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -262,50 +262,47 @@ daemonUnixSocketPaths(struct daemonConfig *config, char **rosockfile, char **admsockfile) { + int ret =3D -1; + char *rundir =3D NULL; + if (config->unix_sock_dir) { if (virAsprintf(sockfile, "%s/libvirt-sock", config->unix_sock_dir= ) < 0) - goto error; + goto cleanup; =20 if (privileged) { - if (virAsprintf(rosockfile, "%s/libvirt-sock-ro", config->unix= _sock_dir) < 0) - goto error; - if (virAsprintf(admsockfile, "%s/libvirt-admin-sock", config->= unix_sock_dir) < 0) - goto error; + if (virAsprintf(rosockfile, "%s/libvirt-sock-ro", config->unix= _sock_dir) < 0 || + virAsprintf(admsockfile, "%s/libvirt-admin-sock", config->= unix_sock_dir) < 0) + goto cleanup; } } else { if (privileged) { if (VIR_STRDUP(*sockfile, LOCALSTATEDIR "/run/libvirt/libvirt-= sock") < 0 || VIR_STRDUP(*rosockfile, LOCALSTATEDIR "/run/libvirt/libvir= t-sock-ro") < 0 || VIR_STRDUP(*admsockfile, LOCALSTATEDIR "/run/libvirt/libvi= rt-admin-sock") < 0) - goto error; + goto cleanup; } else { - char *rundir =3D NULL; mode_t old_umask; =20 if (!(rundir =3D virGetUserRuntimeDirectory())) - goto error; + goto cleanup; =20 old_umask =3D umask(077); if (virFileMakePath(rundir) < 0) { umask(old_umask); - VIR_FREE(rundir); - goto error; + goto cleanup; } umask(old_umask); =20 if (virAsprintf(sockfile, "%s/libvirt-sock", rundir) < 0 || - virAsprintf(admsockfile, "%s/libvirt-admin-sock", rundir) = < 0) { - VIR_FREE(rundir); - goto error; - } - - VIR_FREE(rundir); + virAsprintf(admsockfile, "%s/libvirt-admin-sock", rundir) = < 0) + goto cleanup; } } - return 0; =20 - error: - return -1; + ret =3D 0; + cleanup: + VIR_FREE(rundir); + return ret; } =20 =20 --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list