From nobody Wed May 14 01:27:44 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 1528124769420702.4833240014613; Mon, 4 Jun 2018 08:06:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7AFF8C0D1FBC; Mon, 4 Jun 2018 15:06:07 +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 27ED0600C4; Mon, 4 Jun 2018 15:06:07 +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 8EC5A4CA81; Mon, 4 Jun 2018 15:06:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w54Eb7JC008212 for ; Mon, 4 Jun 2018 10:37:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id DB6118B336; Mon, 4 Jun 2018 14:37:07 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D41638B327 for ; Mon, 4 Jun 2018 14:37:07 +0000 (UTC) Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) (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 D13B73003C7B for ; Mon, 4 Jun 2018 14:36:56 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id w7-v6so690524pfn.9 for ; Mon, 04 Jun 2018 07:36:56 -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.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36:55 -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=ssrCY465CBfTImnKaGCPXyj1RsMn32r7WPHZBtmK0wM=; b=lQ75RQbD+hF+bUThUbBoKV53WfgnjYv43YJQ1TARyY4hgaOIfpaKv0s9bq8cmcHJJC eb1vFMdV/rFOTdMfzqFI+nA5WuaDTpCygHpfmF2dQfog8DYbhf3O8QEPlO6fP5DxdJzd lrUntGfKo6eghKXWuzvG//f+nPJ/jfQ30YIr2eXMNeD/aS5xCUPP4Siv3/Y0030xXcxh f6LuxWNy96PzUWFibyPXe/cGWyRWGws5M9Dfp1YQm+Iyz3qM3xEciVWu/03LShR05jBt xzVbwSi0FE7QYkeGby1JayDc9/6biY6SW4he/KyKxY2HVWtNXBVrtYhKCrDTbE62tbpG rORw== 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=ssrCY465CBfTImnKaGCPXyj1RsMn32r7WPHZBtmK0wM=; b=QiKjzTR6FD/579aa2wEAmKWK/JX3fEAu8YZe0sMw9rv9zzpepFmfxP3x0pJemK6Fn3 N+5fJmJHOudNgAfqEZqMOb7u5PfwwVvo+d98MvHM+Dx/IJIcgFE0G4A/IkVt7eNU7/0j yAbZy397YysS8e5wBvEz1M6QUKwx35mKXqxBdpnRI78pXkVKqxFk1jD05JYxg0wuV90V QRMlLBLK3g7nldfGsstnOlm6G/UDBLCDCDXpOkTScBRZ+eVo7xYdTQS7WRrnJH1afzGp 64Ne8Q/FYzexkeBVQrCdjQCw++xfWaRH1k1Ic7+I75AZ+KjL0pQMfdYpC87v2qOw8O+O ShTg== X-Gm-Message-State: APt69E3mualR0P8kdYQHymZZIIJaOEbD/MpSYl1u9BXYy1M9tsv5NCqD eu+kqMwW9iQgD6YIEkxX66U8qLeM X-Google-Smtp-Source: ADUXVKIviNbqvfV1QIv7vPfbjb9D8ZhOKv2ruflUih8zGfGjqxm9nfS1vmo+9BU4hktudFK12mvk8Q== X-Received: by 2002:a63:721d:: with SMTP id n29-v6mr5230238pgc.194.1528123016025; Mon, 04 Jun 2018 07:36:56 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:13 +0530 Message-Id: <1528013536-22196-16-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.44]); Mon, 04 Jun 2018 14:36:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 04 Jun 2018 14:36:56 +0000 (UTC) for IP:'209.85.192.195' DOMAIN:'mail-pf0-f195.google.com' HELO:'mail-pf0-f195.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.991 (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.192.195 mail-pf0-f195.google.com 209.85.192.195 mail-pf0-f195.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 15/18] use VIR_AUTOFREE in src/util/virconf.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.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 04 Jun 2018 15:06:08 +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/virconf.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/src/util/virconf.c b/src/util/virconf.c index e0a3fd1..7dd8820 100644 --- a/src/util/virconf.c +++ b/src/util/virconf.c @@ -745,9 +745,8 @@ virConfParse(const char *filename, const char *content,= int len, virConfPtr virConfReadFile(const char *filename, unsigned int flags) { - char *content; + VIR_AUTOFREE(char *) content =3D NULL; int len; - virConfPtr conf; =20 VIR_DEBUG("filename=3D%s", NULLSTR(filename)); =20 @@ -759,11 +758,7 @@ virConfReadFile(const char *filename, unsigned int fla= gs) if ((len =3D virFileReadAll(filename, MAX_CONFIG_FILE_SIZE, &content))= < 0) return NULL; =20 - conf =3D virConfParse(filename, content, len, flags); - - VIR_FREE(content); - - return conf; + return virConfParse(filename, content, len, flags); } =20 /** @@ -1451,7 +1446,7 @@ virConfWriteFile(const char *filename, virConfPtr con= f) virConfEntryPtr cur; int ret; int fd; - char *content; + VIR_AUTOFREE(char *) content =3D NULL; unsigned int use; =20 if (conf =3D=3D NULL) @@ -1476,7 +1471,6 @@ virConfWriteFile(const char *filename, virConfPtr con= f) use =3D virBufferUse(&buf); content =3D virBufferContentAndReset(&buf); ret =3D safewrite(fd, content, use); - VIR_FREE(content); VIR_FORCE_CLOSE(fd); if (ret !=3D (int)use) { virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to save content= ")); @@ -1504,7 +1498,7 @@ virConfWriteMem(char *memory, int *len, virConfPtr co= nf) { virBuffer buf =3D VIR_BUFFER_INITIALIZER; virConfEntryPtr cur; - char *content; + VIR_AUTOFREE(char *) content =3D NULL; unsigned int use; =20 if ((memory =3D=3D NULL) || (len =3D=3D NULL) || (*len <=3D 0) || (con= f =3D=3D NULL)) @@ -1524,11 +1518,9 @@ virConfWriteMem(char *memory, int *len, virConfPtr c= onf) =20 if ((int)use >=3D *len) { *len =3D (int)use; - VIR_FREE(content); return -1; } memcpy(memory, content, use); - VIR_FREE(content); *len =3D use; return use; } @@ -1542,16 +1534,13 @@ virConfLoadConfigPath(const char *name) SYSCONFDIR, name) < 0) return NULL; } else { - char *userdir =3D virGetUserConfigDirectory(); + VIR_AUTOFREE(char *) userdir =3D virGetUserConfigDirectory(); if (!userdir) return NULL; =20 if (virAsprintf(&path, "%s/%s", - userdir, name) < 0) { - VIR_FREE(userdir); + userdir, name) < 0) return NULL; - } - VIR_FREE(userdir); } =20 return path; @@ -1560,26 +1549,19 @@ virConfLoadConfigPath(const char *name) int virConfLoadConfig(virConfPtr *conf, const char *name) { - char *path =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; =20 *conf =3D NULL; =20 if (!(path =3D virConfLoadConfigPath(name))) - goto cleanup; + return -1; =20 - if (!virFileExists(path)) { - ret =3D 0; - goto cleanup; - } + if (!virFileExists(path)) + return 0; =20 VIR_DEBUG("Loading config file '%s'", path); if (!(*conf =3D virConfReadFile(path, 0))) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(path); - return ret; + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list