From nobody Wed May 14 01:25:34 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 1528124583002443.45959350471344; Mon, 4 Jun 2018 08:03:03 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 32281DCA39; Mon, 4 Jun 2018 15:03:00 +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 6180227081; Mon, 4 Jun 2018 15:02:59 +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 667CE1800FC1; Mon, 4 Jun 2018 15:02:58 +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 w54EauX9008148 for ; Mon, 4 Jun 2018 10:36:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id E0E485C8AB; Mon, 4 Jun 2018 14:36:56 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D4F535C8AA for ; Mon, 4 Jun 2018 14:36:56 +0000 (UTC) Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) (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 D770BD818D for ; Mon, 4 Jun 2018 14:36:44 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id i5-v6so19842197plt.2 for ; Mon, 04 Jun 2018 07:36:44 -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.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36:43 -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=XEGuHtOkhQTUYkLG6m9ILG8TY8RfpxK231Ie4XGS5R8=; b=N0JZcmpD4u7Tc99aXKnKkamMB5j0BNXzWRuppm9wX8o8aL02exSnWNHXXHJiH6m+HM bW67MbtS6faj16mcv16Rpwq0IUVtMQ4fBHTJHlJT+QXgqv/QRxr4ctK4Xdv2bQK6QmnH zV/orgTviLOxdN94ll/SbLBwkVvhZrVNnhxSGnTpFOSNeBrWTSYPsAZ7UD4PTn/7S/bR Eu5DFmHPBZpH4T26aeYUCkmaOo90Wn3kS8PjjHouneO7Wxf3C5Ft4KGQGGz6xDyRUrnl +r5nWph1rOiTh4/XXp8++XxD/coU0VhdP7flElRSXTfLSuhgVitnwD4Dxv9U5OgMekke 8EKw== 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=XEGuHtOkhQTUYkLG6m9ILG8TY8RfpxK231Ie4XGS5R8=; b=ieTkU/s3OH/HywWKfFDHoXk0zkyGEdX1/gkJC+xM2HrF0bxcYbDSFtduKCYVMV4VU8 G5/H/Cw5etH4ARRe2iaAho+gdnUiUnnTzuPx/Xw/X7rZgfcWpLppM1JZ7n1+4+r6LKhh Lrw3RL4IT3jmOLFKwFnrGp7TDv+Tn7nd7blLlg7bE3X8FhHrrBJluiR6uEwbQobm0lRJ qrPflIcQ48ytLy0jQaeCgK9dF5cztvt5WEcOgIOHKeH2FN/AqD/wVfvodlllHgzkmKVC CyPrKTzTiD/2aGerAjVTwARd6Sf6ehnhVnWU0oFVGX55mBJ0qEm4Ep1O+RxOCjamzmqV iP5g== X-Gm-Message-State: APt69E31b8Ix0FoRS3YLCe0SRfgPRpuV0k14vTFi/l40zE2YXGFru9Ko S1IVUaGgofZrlL5cjgE2IWPX4ihZ X-Google-Smtp-Source: ADUXVKI9Qa1uTHsT6dMyQ7AMxhYe4sAdtk7V1bNOTyzhepWZVlkV6suHoLB0riGFctW8JY1wq6Xdag== X-Received: by 2002:a17:902:854a:: with SMTP id d10-v6mr12146733plo.106.1528123003943; Mon, 04 Jun 2018 07:36:43 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:08 +0530 Message-Id: <1528013536-22196-11-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.30]); Mon, 04 Jun 2018 14:36:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 04 Jun 2018 14:36:45 +0000 (UTC) for IP:'209.85.160.68' DOMAIN:'mail-pl0-f68.google.com' HELO:'mail-pl0-f68.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) 209.85.160.68 mail-pl0-f68.google.com 209.85.160.68 mail-pl0-f68.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 10/18] use VIR_AUTOFREE in src/util/virdnsmasq.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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 04 Jun 2018 15:03:01 +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/virdnsmasq.c | 116 +++++++++++++++++-----------------------------= ---- 1 file changed, 39 insertions(+), 77 deletions(-) diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index 492dcad..c806cd2 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -95,7 +95,7 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile, virSocketAddr *ip, const char *name) { - char *ipstr =3D NULL; + VIR_AUTOFREE(char *) ipstr =3D NULL; int idx =3D -1; size_t i; =20 @@ -111,35 +111,29 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile, =20 if (idx < 0) { if (VIR_REALLOC_N(addnhostsfile->hosts, addnhostsfile->nhosts + 1)= < 0) - goto error; + return -1; =20 idx =3D addnhostsfile->nhosts; if (VIR_ALLOC(addnhostsfile->hosts[idx].hostnames) < 0) - goto error; + return -1; =20 if (VIR_STRDUP(addnhostsfile->hosts[idx].ip, ipstr) < 0) - goto error; + return -1; =20 addnhostsfile->hosts[idx].nhostnames =3D 0; addnhostsfile->nhosts++; } =20 if (VIR_REALLOC_N(addnhostsfile->hosts[idx].hostnames, addnhostsfile->= hosts[idx].nhostnames + 1) < 0) - goto error; + return -1; =20 if (VIR_STRDUP(addnhostsfile->hosts[idx].hostnames[addnhostsfile->host= s[idx].nhostnames], name) < 0) - goto error; - - VIR_FREE(ipstr); + return -1; =20 addnhostsfile->hosts[idx].nhostnames++; =20 return 0; - - error: - VIR_FREE(ipstr); - return -1; } =20 static dnsmasqAddnHostsfile * @@ -178,11 +172,10 @@ addnhostsWrite(const char *path, dnsmasqAddnHost *hosts, unsigned int nhosts) { - char *tmp; + VIR_AUTOFREE(char *) tmp =3D NULL; FILE *f; bool istmp =3D true; size_t i, j; - int rc =3D 0; =20 /* even if there are 0 hosts, create a 0 length file, to allow * for runtime addition. @@ -193,61 +186,50 @@ addnhostsWrite(const char *path, =20 if (!(f =3D fopen(tmp, "w"))) { istmp =3D false; - if (!(f =3D fopen(path, "w"))) { - rc =3D -errno; - goto cleanup; - } + if (!(f =3D fopen(path, "w"))) + return -errno; } =20 for (i =3D 0; i < nhosts; i++) { if (fputs(hosts[i].ip, f) =3D=3D EOF || fputc('\t', f) =3D=3D EOF)= { - rc =3D -errno; VIR_FORCE_FCLOSE(f); =20 if (istmp) unlink(tmp); =20 - goto cleanup; + return -errno; } =20 for (j =3D 0; j < hosts[i].nhostnames; j++) { if (fputs(hosts[i].hostnames[j], f) =3D=3D EOF || fputc('\t', = f) =3D=3D EOF) { - rc =3D -errno; VIR_FORCE_FCLOSE(f); =20 if (istmp) unlink(tmp); =20 - goto cleanup; + return -errno; } } =20 if (fputc('\n', f) =3D=3D EOF) { - rc =3D -errno; VIR_FORCE_FCLOSE(f); =20 if (istmp) unlink(tmp); =20 - goto cleanup; + return -errno; } } =20 - if (VIR_FCLOSE(f) =3D=3D EOF) { - rc =3D -errno; - goto cleanup; - } + if (VIR_FCLOSE(f) =3D=3D EOF) + return -errno; =20 if (istmp && rename(tmp, path) < 0) { - rc =3D -errno; unlink(tmp); - goto cleanup; + return -errno; } =20 - cleanup: - VIR_FREE(tmp); - - return rc; + return 0; } =20 static int @@ -310,9 +292,10 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile, const char *id, bool ipv6) { - char *ipstr =3D NULL; + VIR_AUTOFREE(char *) ipstr =3D NULL; + if (VIR_REALLOC_N(hostsfile->hosts, hostsfile->nhosts + 1) < 0) - goto error; + return -1; =20 if (!(ipstr =3D virSocketAddrFormat(ip))) return -1; @@ -322,38 +305,33 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile, if (name && id) { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "id:%s,%s,[%s]", id, name, ipstr) < 0) - goto error; + return -1; } else if (name && !id) { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,[%s]", name, ipstr) < 0) - goto error; + return -1; } else if (!name && id) { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "id:%s,[%s]", id, ipstr) < 0) - goto error; + return -1; } } else if (name && mac) { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s,= %s", mac, ipstr, name) < 0) - goto error; + return -1; } else if (name && !mac) { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s", name, ipstr) < 0) - goto error; + return -1; } else { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s", mac, ipstr) < 0) - goto error; + return -1; } - VIR_FREE(ipstr); =20 hostsfile->nhosts++; =20 return 0; - - error: - VIR_FREE(ipstr); - return -1; } =20 static dnsmasqHostsfile * @@ -391,11 +369,10 @@ hostsfileWrite(const char *path, dnsmasqDhcpHost *hosts, unsigned int nhosts) { - char *tmp; + VIR_AUTOFREE(char *) tmp =3D NULL; FILE *f; bool istmp =3D true; size_t i; - int rc =3D 0; =20 /* even if there are 0 hosts, create a 0 length file, to allow * for runtime addition. @@ -406,39 +383,30 @@ hostsfileWrite(const char *path, =20 if (!(f =3D fopen(tmp, "w"))) { istmp =3D false; - if (!(f =3D fopen(path, "w"))) { - rc =3D -errno; - goto cleanup; - } + if (!(f =3D fopen(path, "w"))) + return -errno; } =20 for (i =3D 0; i < nhosts; i++) { if (fputs(hosts[i].host, f) =3D=3D EOF || fputc('\n', f) =3D=3D EO= F) { - rc =3D -errno; VIR_FORCE_FCLOSE(f); =20 if (istmp) unlink(tmp); =20 - goto cleanup; + return -errno; } } =20 - if (VIR_FCLOSE(f) =3D=3D EOF) { - rc =3D -errno; - goto cleanup; - } + if (VIR_FCLOSE(f) =3D=3D EOF) + return -errno; =20 if (istmp && rename(tmp, path) < 0) { - rc =3D -errno; unlink(tmp); - goto cleanup; + return -errno; } =20 - cleanup: - VIR_FREE(tmp); - - return rc; + return 0; } =20 static int @@ -708,17 +676,12 @@ dnsmasqCapsSetFromBuffer(dnsmasqCapsPtr caps, const c= har *buf) static int dnsmasqCapsSetFromFile(dnsmasqCapsPtr caps, const char *path) { - int ret =3D -1; - char *buf =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if (virFileReadAll(path, 1024 * 1024, &buf) < 0) - goto cleanup; - - ret =3D dnsmasqCapsSetFromBuffer(caps, buf); + return -1; =20 - cleanup: - VIR_FREE(buf); - return ret; + return dnsmasqCapsSetFromBuffer(caps, buf); } =20 static int @@ -727,7 +690,9 @@ dnsmasqCapsRefreshInternal(dnsmasqCapsPtr caps, bool fo= rce) int ret =3D -1; struct stat sb; virCommandPtr cmd =3D NULL; - char *help =3D NULL, *version =3D NULL, *complete =3D NULL; + VIR_AUTOFREE(char *) help =3D NULL; + VIR_AUTOFREE(char *) version =3D NULL; + VIR_AUTOFREE(char *) complete =3D NULL; =20 if (!caps || caps->noRefresh) return 0; @@ -779,9 +744,6 @@ dnsmasqCapsRefreshInternal(dnsmasqCapsPtr caps, bool fo= rce) =20 cleanup: virCommandFree(cmd); - VIR_FREE(help); - VIR_FREE(version); - VIR_FREE(complete); return ret; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list