From nobody Sun May 5 18:39:04 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550851492730302.1301586020368; Fri, 22 Feb 2019 08:04:52 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF8607DCC2; Fri, 22 Feb 2019 16:04: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 8F8DE5D9CA; Fri, 22 Feb 2019 16:04:50 +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 3DD5241F3F; Fri, 22 Feb 2019 16:04:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1MG4jrt015181 for ; Fri, 22 Feb 2019 11:04:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 808405D9D4; Fri, 22 Feb 2019 16:04:45 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 066785D9CA for ; Fri, 22 Feb 2019 16:04:44 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 22 Feb 2019 17:04:37 +0100 Message-Id: <5d0750659d94f4359813b363421e1df673dda8f0.1550851418.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/4] util: alloc: Remove pointless clearing of variable in AUTOPTR_FUNCs 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: , 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 22 Feb 2019 16:04:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" VIR_DEFINE_AUTOPTR_FUNC defines a function which is supposed to free the resources for the given VIR_AUTOPTR variable. Given that the cleanup function is executed when the stack frame is being destroyed it does not make much sense to set the pointer to NULL. Making the inline function contain less code also decreases the possibility that for a given type the inlining will be declined by the compiler due to increasing code size. Signed-off-by: Peter Krempa --- src/util/viralloc.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 15451d4673..50a07d4fa3 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -612,7 +612,6 @@ void virAllocTestHook(void (*func)(int, void*), void *d= ata); { \ if (*_ptr) \ (func)(*_ptr); \ - *_ptr =3D NULL; \ } # define VIR_AUTOCLEAN_FUNC_NAME(type) type##AutoClean --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:39:04 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550851501081365.84943067284144; Fri, 22 Feb 2019 08:05:01 -0800 (PST) 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 25974307FBCB; Fri, 22 Feb 2019 16:04:59 +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 D61EF6017E; Fri, 22 Feb 2019 16:04:58 +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 7F9D7181A00D; Fri, 22 Feb 2019 16:04:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1MG4kAI015187 for ; Fri, 22 Feb 2019 11:04:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5721A5D9D5; Fri, 22 Feb 2019 16:04:46 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0DB45D9CA for ; Fri, 22 Feb 2019 16:04:45 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 22 Feb 2019 17:04:38 +0100 Message-Id: <2aefd47b2267bd76720c7e24e2ae440e428ecdac.1550851418.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/4] util: alloc: Introduce macro for self-freeing NULL-terminated lists 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: , 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.41]); Fri, 22 Feb 2019 16:04:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" VIR_AUTOLISTPTR allows you to define a pointer to a NULL-terminated list of elements which will be auto-freed when destroying the scope. This is done so that we can avoid using VIR_AUTOPTR in those cases as it worked only for virStringList-related stuff. Signed-off-by: Peter Krempa --- src/util/viralloc.h | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 50a07d4fa3..983a6e83d1 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -631,6 +631,54 @@ void virAllocTestHook(void (*func)(int, void*), void *= data); (func)(_ptr); \ } + +# define VIR_AUTOLISTPTR_FUNC_NAME(type) type##AutoListPtrFree + +/** + * VIR_DEFINE_AUTOLISTPTR_FUNC: + * @type: type of the element of the list + * @func: freeing function for a single element of the list + * + * This macro defines the freeing function used by VIR_AUTOLISTPTR for @ty= pe. + * @func must free one of the elements of @type. + * + * Note that the function is not inline due to size and thus + * VIR_DECLARE_AUTOLISTPTR_FUNC needs to be used in the appropriate header= file. + * + * VIR_DEFINE_AUTOLISTPTR_FUNC is mutually exclusive with + * VIR_DEFINE_AUTOLISTPTR_FUNC_DIRECT. + */ +# define VIR_DECLARE_AUTOLISTPTR_FUNC(type) \ + void VIR_AUTOLISTPTR_FUNC_NAME(type)(type **_ptr); +# define VIR_DEFINE_AUTOLISTPTR_FUNC(type, func) \ + void VIR_AUTOLISTPTR_FUNC_NAME(type)(type **_ptr) \ + { \ + type *n;\ + for (n =3D *_ptr; n && *n; n++) \ + (func)(n); \ + VIR_FREE(*_ptr);\ + } + +/** + * VIR_DEFINE_AUTOLISTPTR_FUNC_DIRECT: + * @type: type of the element of the list + * @func: freeing function for the whole NULL-terminated list of @type + * + * This macro defines the freeing function used by VIR_AUTOLISTPTR for @ty= pe. + * @func must free a NULL terminated dense list of @type and also the list + * itself. This is a convenience option if @type has already such function. + * + * VIR_DEFINE_AUTOLISTPTR_FUNC_DIRECT is mutually exclusive with + * VIR_DEFINE_AUTOLISTPTR_FUNC. + */ +# define VIR_DEFINE_AUTOLISTPTR_FUNC_DIRECT(type, func) \ + static inline void VIR_AUTOLISTPTR_FUNC_NAME(type)(type **_ptr) \ + { \ + if (*_ptr) \ + (func)(*_ptr); \ + } + + /** * VIR_AUTOFREE: * @type: type of the variable to be freed automatically @@ -665,6 +713,19 @@ void virAllocTestHook(void (*func)(int, void*), void *= data); # define VIR_AUTOCLEAN(type) \ __attribute__((cleanup(VIR_AUTOCLEAN_FUNC_NAME(type)))) type +/** + * VIR_AUTOLISTPTR: + * @type: type of the members of the self-freeing NULL-terminated list to = be defined + * + * This macro defines a pointer to a NULL-terminated list of @type members= . The + * list is automatically freed when it goes out of scope including elements + * themselves. + * + * The freeing function is registered by VIR_DEFINE_AUTOLISTPTR_FUNC or + * VIR_DEFINE_AUTOLISTPTR_FUNC_DIRECT macro for the given type. + */ +# define VIR_AUTOLISTPTR(type) \ + __attribute__((cleanup(VIR_AUTOLISTPTR_FUNC_NAME(type)))) type * /** * VIR_AUTOUNREF: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:39:04 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550851505137408.4759465171005; Fri, 22 Feb 2019 08:05:05 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED09C306E171; Fri, 22 Feb 2019 16:05:02 +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 B74E11001E99; Fri, 22 Feb 2019 16:05:02 +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 451873FB11; Fri, 22 Feb 2019 16:05:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1MG4lAk015195 for ; Fri, 22 Feb 2019 11:04:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2E08E5D9D4; Fri, 22 Feb 2019 16:04:47 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id A77EF5D9CA for ; Fri, 22 Feb 2019 16:04:46 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 22 Feb 2019 17:04:39 +0100 Message-Id: <990c7d04f3f6f25e08729fc6cfa8df8f0dd8a4c8.1550851418.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/4] util: string: Use VIR_AUTOLISTPTR for 'virString' 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 22 Feb 2019 16:05:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" VIR_AUTOPTR should not be used for vectors except for the rare case of NULL-terminated lists. Convert all cases of usage of VIR_AUTOPTR for 'virString' to VIR_AUTOLISTPTR. Signed-off-by: Peter Krempa --- src/lxc/lxc_process.c | 2 +- src/qemu/qemu_conf.c | 8 ++++---- src/storage/storage_backend_sheepdog.c | 4 ++-- src/storage/storage_backend_zfs.c | 10 +++++----- src/util/vircommand.c | 2 +- src/util/virfirewall.c | 2 +- src/util/virprocess.c | 2 +- src/util/virstoragefile.c | 10 +++++----- src/util/virstring.h | 2 +- src/xenconfig/xen_common.c | 6 +++--- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index a3481bfa08..566ed13fda 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1181,7 +1181,7 @@ int virLXCProcessStart(virConnectPtr conn, size_t i; char *logfile =3D NULL; int logfd =3D -1; - VIR_AUTOPTR(virString) veths =3D NULL; + VIR_AUTOLISTPTR(virString) veths =3D NULL; int handshakefds[2] =3D { -1, -1 }; off_t pos =3D -1; char ebuf[1024]; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 2f5ef8d0c4..72a0b97772 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -645,7 +645,7 @@ static int virQEMUDriverConfigLoadProcessEntry(virQEMUDriverConfigPtr cfg, virConfPtr conf) { - VIR_AUTOPTR(virString) hugetlbfs =3D NULL; + VIR_AUTOLISTPTR(virString) hugetlbfs =3D NULL; VIR_AUTOFREE(char *) stdioHandler =3D NULL; VIR_AUTOFREE(char *) corestr =3D NULL; size_t i; @@ -832,7 +832,7 @@ static int virQEMUDriverConfigLoadNVRAMEntry(virQEMUDriverConfigPtr cfg, virConfPtr conf) { - VIR_AUTOPTR(virString) nvram =3D NULL; + VIR_AUTOLISTPTR(virString) nvram =3D NULL; size_t i; if (virConfGetValueStringList(conf, "nvram", false, &nvram) < 0) @@ -869,8 +869,8 @@ virQEMUDriverConfigLoadSecurityEntry(virQEMUDriverConfi= gPtr cfg, virConfPtr conf, bool privileged) { - VIR_AUTOPTR(virString) controllers =3D NULL; - VIR_AUTOPTR(virString) namespaces =3D NULL; + VIR_AUTOLISTPTR(virString) controllers =3D NULL; + VIR_AUTOLISTPTR(virString) namespaces =3D NULL; VIR_AUTOFREE(char *) user =3D NULL; VIR_AUTOFREE(char *) group =3D NULL; size_t i, j; diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_b= ackend_sheepdog.c index 99f3283a1c..4c01207409 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -138,8 +138,8 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolOb= jPtr pool) { size_t i; VIR_AUTOFREE(char *) output =3D NULL; - VIR_AUTOPTR(virString) lines =3D NULL; - VIR_AUTOPTR(virString) cells =3D NULL; + VIR_AUTOLISTPTR(virString) lines =3D NULL; + VIR_AUTOLISTPTR(virString) cells =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; cmd =3D virCommandNewArgList(SHEEPDOGCLI, "vdi", "list", "-r", NULL); diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backen= d_zfs.c index 7ffdff638e..25f9e90f98 100644 --- a/src/storage/storage_backend_zfs.c +++ b/src/storage/storage_backend_zfs.c @@ -106,8 +106,8 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr pool, bool is_new_vol =3D false; virStorageVolDefPtr volume =3D NULL; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); - VIR_AUTOPTR(virString) tokens =3D NULL; - VIR_AUTOPTR(virString) name_tokens =3D NULL; + VIR_AUTOLISTPTR(virString) tokens =3D NULL; + VIR_AUTOLISTPTR(virString) name_tokens =3D NULL; if (!(tokens =3D virStringSplitCount(volume_string, "\t", 0, &count))) return -1; @@ -177,7 +177,7 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool, { virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); size_t i; - VIR_AUTOPTR(virString) lines =3D NULL; + VIR_AUTOLISTPTR(virString) lines =3D NULL; VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) volumes_list =3D NULL; @@ -224,8 +224,8 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr po= ol ATTRIBUTE_UNUSED) char *zpool_props =3D NULL; size_t i; VIR_AUTOPTR(virCommand) cmd =3D NULL; - VIR_AUTOPTR(virString) lines =3D NULL; - VIR_AUTOPTR(virString) tokens =3D NULL; + VIR_AUTOLISTPTR(virString) lines =3D NULL; + VIR_AUTOLISTPTR(virString) tokens =3D NULL; /** * $ zpool get -Hp health,size,free,allocated test diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 3d533c68a6..8d8862ad85 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -2983,7 +2983,7 @@ virCommandRunRegex(virCommandPtr cmd, int totgroups =3D 0, ngroup =3D 0, maxvars =3D 0; char **groups; VIR_AUTOFREE(char *) outbuf =3D NULL; - VIR_AUTOPTR(virString) lines =3D NULL; + VIR_AUTOLISTPTR(virString) lines =3D NULL; int ret =3D -1; /* Compile all regular expressions */ diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c index d63ce05ed8..2b7620f943 100644 --- a/src/util/virfirewall.c +++ b/src/util/virfirewall.c @@ -719,7 +719,7 @@ virFirewallApplyRule(virFirewallPtr firewall, { VIR_AUTOFREE(char *) output =3D NULL; VIR_AUTOFREE(char *) str =3D virFirewallRuleToString(rule); - VIR_AUTOPTR(virString) lines =3D NULL; + VIR_AUTOLISTPTR(virString) lines =3D NULL; VIR_INFO("Applying rule '%s'", NULLSTR(str)); if (rule->ignoreErrors) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 4e69228f34..80aba1e44d 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -987,7 +987,7 @@ int virProcessGetStartTime(pid_t pid, int len; VIR_AUTOFREE(char *) filename =3D NULL; VIR_AUTOFREE(char *) buf =3D NULL; - VIR_AUTOPTR(virString) tokens =3D NULL; + VIR_AUTOLISTPTR(virString) tokens =3D NULL; if (virAsprintf(&filename, "/proc/%llu/stat", (long long) pid) < 0) return -1; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index b2e308d81d..87ce299e64 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1571,7 +1571,7 @@ virStorageFileParseBackingStoreStr(const char *str, size_t nstrings; unsigned int idx =3D 0; char *suffix; - VIR_AUTOPTR(virString) strings =3D NULL; + VIR_AUTOLISTPTR(virString) strings =3D NULL; *chainIndex =3D 0; @@ -2661,7 +2661,7 @@ virStorageSourceParseBackingURI(virStorageSourcePtr s= rc, virURIPtr uri =3D NULL; const char *path =3D NULL; int ret =3D -1; - VIR_AUTOPTR(virString) scheme =3D NULL; + VIR_AUTOLISTPTR(virString) scheme =3D NULL; if (!(uri =3D virURIParse(uristr))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2765,7 +2765,7 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src, { char *port; size_t skip; - VIR_AUTOPTR(virString) parts =3D NULL; + VIR_AUTOLISTPTR(virString) parts =3D NULL; if (VIR_EXPAND_N(src->hosts, src->nhosts, 1) < 0) return -1; @@ -2921,7 +2921,7 @@ static int virStorageSourceParseNBDColonString(const char *nbdstr, virStorageSourcePtr src) { - VIR_AUTOPTR(virString) backing =3D NULL; + VIR_AUTOLISTPTR(virString) backing =3D NULL; if (!(backing =3D virStringSplit(nbdstr, ":", 0))) return -1; @@ -4208,7 +4208,7 @@ int virStorageFileCheckCompat(const char *compat) { unsigned int result; - VIR_AUTOPTR(virString) version =3D NULL; + VIR_AUTOLISTPTR(virString) version =3D NULL; if (!compat) return 0; diff --git a/src/util/virstring.h b/src/util/virstring.h index aef82471c2..b2c7178686 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -307,6 +307,6 @@ int virStringParsePort(const char *str, unsigned int *port) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; -VIR_DEFINE_AUTOPTR_FUNC(virString, virStringListFree); +VIR_DEFINE_AUTOLISTPTR_FUNC_DIRECT(virString, virStringListFree); #endif /* LIBVIRT_VIRSTRING_H */ diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 94e0703cf3..6b0bdcb178 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -473,7 +473,7 @@ xenHandleConfGetValueStringListErrors(int ret) static int xenParsePCIList(virConfPtr conf, virDomainDefPtr def) { - VIR_AUTOPTR(virString) pcis =3D NULL; + VIR_AUTOLISTPTR(virString) pcis =3D NULL; virString *entries =3D NULL; int rc; @@ -666,7 +666,7 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) } if (!hvm && def->graphics =3D=3D NULL) { /* New PV guests use this for= mat */ - VIR_AUTOPTR(virString) vfbs =3D NULL; + VIR_AUTOLISTPTR(virString) vfbs =3D NULL; int rc; if ((rc =3D virConfGetValueStringList(conf, "vfb", false, &vfbs)) = =3D=3D 1) { @@ -764,7 +764,7 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) static int xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFo= rmat) { - VIR_AUTOPTR(virString) serials =3D NULL; + VIR_AUTOLISTPTR(virString) serials =3D NULL; virDomainChrDefPtr chr =3D NULL; if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:39:04 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550851510508128.84202986985167; Fri, 22 Feb 2019 08:05:10 -0800 (PST) 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 634F3307D987; Fri, 22 Feb 2019 16:05:08 +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 30ADB5D717; Fri, 22 Feb 2019 16:05:08 +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 C58CA3FB14; Fri, 22 Feb 2019 16:05:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1MG4m2R015204 for ; Fri, 22 Feb 2019 11:04:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 033F15D9D4; Fri, 22 Feb 2019 16:04:48 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D0AA5D9CA for ; Fri, 22 Feb 2019 16:04:47 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 22 Feb 2019 17:04:40 +0100 Message-Id: <997bc45115d5c47acbc9b974d58da913b127e96f.1550851418.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/4] util: alloc: Note that VIR_AUTOPTR/VIR_AUTOCLEAN must not be used with vectors 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: , 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.48]); Fri, 22 Feb 2019 16:05:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We'd free only the first element of the vector leaking the rest. Signed-off-by: Peter Krempa --- src/util/viralloc.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 983a6e83d1..6de311259d 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -697,6 +697,10 @@ void virAllocTestHook(void (*func)(int, void*), void *= data); * the variable declared with it by calling the function * defined by VIR_DEFINE_AUTOPTR_FUNC when the variable * goes out of scope. + * + * Note that this macro must NOT be used with vectors! The cleaning functi= on + * will not free any elements beyond the first. + * See VIR_AUTOLISTPTR for NULL-terminated lists. */ # define VIR_AUTOPTR(type) \ __attribute__((cleanup(VIR_AUTOPTR_FUNC_NAME(type)))) type * @@ -709,6 +713,10 @@ void virAllocTestHook(void (*func)(int, void*), void *= data); * when the variable goes out of scope. * The cleanup function is registered by VIR_DEFINE_AUTOCLEAN_FUNC macro f= or * the given type. + * + * Note that this macro must NOT be used with vectors! The cleaning functi= on + * will not free any elements beyond the first. + * See VIR_AUTOLISTPTR for NULL-terminated lists. */ # define VIR_AUTOCLEAN(type) \ __attribute__((cleanup(VIR_AUTOCLEAN_FUNC_NAME(type)))) type --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list