From nobody Mon May 6 12:20:14 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 1551196122477910.997148534698; Tue, 26 Feb 2019 07:48:42 -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 0AF2330FD843; Tue, 26 Feb 2019 15:48:40 +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 B42956012C; Tue, 26 Feb 2019 15:48:39 +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 6A25A181A048; Tue, 26 Feb 2019 15:48:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1QFmW4M014338 for ; Tue, 26 Feb 2019 10:48:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3259C60BFB; Tue, 26 Feb 2019 15:48:32 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84F9760BF4; Tue, 26 Feb 2019 15:48:31 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 26 Feb 2019 16:48:23 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v2 1/4] util: string: Introduce macro for automatic string 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.49]); Tue, 26 Feb 2019 15:48:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Similar to VIR_AUTOPTR, VIR_AUTOSTRINGLIST defines a list of strings which will be freed if the pointer is leaving scope. Signed-off-by: Peter Krempa Reviewed-by: Erik Skultety --- src/libvirt_private.syms | 1 + src/util/virstring.c | 10 ++++++++++ src/util/virstring.h | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 038a744981..e68e3f3a3b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2958,6 +2958,7 @@ virStringHasControlChars; virStringIsEmpty; virStringIsPrintable; virStringListAdd; +virStringListAutoFree; virStringListFree; virStringListFreeCount; virStringListGetFirstWithPrefix; diff --git a/src/util/virstring.c b/src/util/virstring.c index e890dde546..8a791f96d4 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -318,6 +318,16 @@ void virStringListFree(char **strings) } +void virStringListAutoFree(char ***strings) +{ + if (!*strings) + return; + + virStringListFree(*strings); + *strings =3D NULL; +} + + /** * virStringListFreeCount: * @strings: array of strings to free diff --git a/src/util/virstring.h b/src/util/virstring.h index aef82471c2..d14b7f4f49 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -53,6 +53,7 @@ int virStringListCopy(char ***dst, const char **src); void virStringListFree(char **strings); +void virStringListAutoFree(char ***strings); void virStringListFreeCount(char **strings, size_t count); @@ -307,6 +308,15 @@ int virStringParsePort(const char *str, unsigned int *port) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; +/** + * VIR_AUTOSTRINGLIST: + * + * Declares a NULL-terminated list of strings which will be automatically = freed + * when the pointer goes out of scope. + */ +# define VIR_AUTOSTRINGLIST \ + __attribute__((cleanup(virStringListAutoFree))) char ** + VIR_DEFINE_AUTOPTR_FUNC(virString, virStringListFree); #endif /* LIBVIRT_VIRSTRING_H */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 12:20:14 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 1551196118885794.9361930260621; Tue, 26 Feb 2019 07:48:38 -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 E177D81113; Tue, 26 Feb 2019 15:48:36 +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 B0B435D6AA; Tue, 26 Feb 2019 15:48:36 +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 5C0733FB16; Tue, 26 Feb 2019 15:48:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1QFmXeY014345 for ; Tue, 26 Feb 2019 10:48:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 31A1960BFB; Tue, 26 Feb 2019 15:48:33 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81B5260BFC; Tue, 26 Feb 2019 15:48:32 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 26 Feb 2019 16:48:24 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v2 2/4] util: string: Use VIR_AUTOSTRINGLIST instead of VIR_AUTOPTR(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.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.28]); Tue, 26 Feb 2019 15:48:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use of VIR_AUTOPTR and virString is confusing as it's a list and not a single pointer. Replace it by VIR_AUTOSTRINGLIST as string lists are basically the only sane NULL-terminated list we can have. Signed-off-by: Peter Krempa Reviewed-by: Erik Skultety --- 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/xenconfig/xen_common.c | 6 +++--- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index a3481bfa08..e0729a24bf 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_AUTOSTRINGLIST 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..42122dcd97 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_AUTOSTRINGLIST 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_AUTOSTRINGLIST 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_AUTOSTRINGLIST controllers =3D NULL; + VIR_AUTOSTRINGLIST 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..6df90937c2 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_AUTOSTRINGLIST lines =3D NULL; + VIR_AUTOSTRINGLIST 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..826a95538e 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_AUTOSTRINGLIST tokens =3D NULL; + VIR_AUTOSTRINGLIST 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_AUTOSTRINGLIST 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_AUTOSTRINGLIST lines =3D NULL; + VIR_AUTOSTRINGLIST 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..84a65a2f6d 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_AUTOSTRINGLIST 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..d42c734ea6 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_AUTOSTRINGLIST 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..52b86c549d 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_AUTOSTRINGLIST 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..f361f96203 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_AUTOSTRINGLIST 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_AUTOSTRINGLIST 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_AUTOSTRINGLIST 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_AUTOSTRINGLIST 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_AUTOSTRINGLIST version =3D NULL; if (!compat) return 0; diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 94e0703cf3..2c8179f19c 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_AUTOSTRINGLIST 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_AUTOSTRINGLIST 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_AUTOSTRINGLIST 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 Mon May 6 12:20:14 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 1551196123438808.2245123430182; Tue, 26 Feb 2019 07:48:43 -0800 (PST) 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 750AE30A7C86; Tue, 26 Feb 2019 15:48:41 +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 456B0289B6; Tue, 26 Feb 2019 15:48:41 +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 07C373FB13; Tue, 26 Feb 2019 15:48:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1QFmY2n014353 for ; Tue, 26 Feb 2019 10:48:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2A9F060BFB; Tue, 26 Feb 2019 15:48:34 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DF7A60BF5; Tue, 26 Feb 2019 15:48:33 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 26 Feb 2019 16:48:25 +0100 Message-Id: <79c0af4fe112a33a0d76e2b19eaf7c436d762bd0.1551196046.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v2 3/4] util: string: Remove the 'virString' type 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 26 Feb 2019 15:48:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We don't need it as there's a separate macro for auto-freeing of string lists. Signed-off-by: Peter Krempa Reviewed-by: Erik Skultety --- src/util/virstring.h | 4 ---- src/xenconfig/xen_common.c | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/util/virstring.h b/src/util/virstring.h index d14b7f4f49..f2e72936c8 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -24,8 +24,6 @@ # include "internal.h" # include "viralloc.h" -typedef char *virString; - char **virStringSplitCount(const char *string, const char *delim, size_t max_tokens, @@ -317,6 +315,4 @@ int virStringParsePort(const char *str, # define VIR_AUTOSTRINGLIST \ __attribute__((cleanup(virStringListAutoFree))) char ** -VIR_DEFINE_AUTOPTR_FUNC(virString, virStringListFree); - #endif /* LIBVIRT_VIRSTRING_H */ diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 2c8179f19c..21c56edd58 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -474,14 +474,14 @@ static int xenParsePCIList(virConfPtr conf, virDomainDefPtr def) { VIR_AUTOSTRINGLIST pcis =3D NULL; - virString *entries =3D NULL; + char **entries =3D NULL; int rc; if ((rc =3D virConfGetValueStringList(conf, "pci", false, &pcis)) <=3D= 0) return xenHandleConfGetValueStringListErrors(rc); for (entries =3D pcis; *entries; entries++) { - virString entry =3D *entries; + char *entry =3D *entries; virDomainHostdevDefPtr hostdev; if (!(hostdev =3D xenParsePCI(entry))) @@ -789,7 +789,7 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, c= onst char *nativeFormat) /* Try to get the list of values to support multiple serial ports = */ if ((rc =3D virConfGetValueStringList(conf, "serial", false, &seri= als)) =3D=3D 1) { - virString *entries; + char **entries; int portnum =3D -1; if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) { @@ -799,7 +799,7 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, c= onst char *nativeFormat) } for (entries =3D serials; *entries; entries++) { - virString port =3D *entries; + char *port =3D *entries; portnum++; if (STREQ(port, "none")) --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 6 12:20:14 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 1551196119384723.6247836590975; Tue, 26 Feb 2019 07:48:39 -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 0C08C30039BE; Tue, 26 Feb 2019 15:48:37 +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 C2DA7600C0; Tue, 26 Feb 2019 15:48:36 +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 0F0AA181A00D; Tue, 26 Feb 2019 15:48:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1QFmZUm014360 for ; Tue, 26 Feb 2019 10:48:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 26DD360BF5; Tue, 26 Feb 2019 15:48:35 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7953160BF4; Tue, 26 Feb 2019 15:48:34 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 26 Feb 2019 16:48:26 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v2 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 26 Feb 2019 15:48:37 +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 Reviewed-by: Erik Skultety --- src/util/viralloc.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 15451d4673..572b7d1c1c 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -650,6 +650,9 @@ void virAllocTestHook(void (*func)(int, void*), void *d= ata); * 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. */ # define VIR_AUTOPTR(type) \ __attribute__((cleanup(VIR_AUTOPTR_FUNC_NAME(type)))) type * @@ -662,6 +665,9 @@ void virAllocTestHook(void (*func)(int, void*), void *d= ata); * 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. */ # 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