From nobody Fri May 3 06:07:30 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 1545059638263645.1108862534311; Mon, 17 Dec 2018 07:13:58 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7149E1E2D4; Mon, 17 Dec 2018 14:56:09 +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 E2A1F2B8AA; Mon, 17 Dec 2018 14:56: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 5E428181BA17; Mon, 17 Dec 2018 14:56:08 +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 wBHEtsjt009326 for ; Mon, 17 Dec 2018 09:55:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7ACF12A2F0; Mon, 17 Dec 2018 14:55:54 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-170.phx2.redhat.com [10.3.116.170]) by smtp.corp.redhat.com (Postfix) with ESMTP id 359445DA2A for ; Mon, 17 Dec 2018 14:55:54 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 17 Dec 2018 09:55:46 -0500 Message-Id: <20181217145548.15125-2-jferlan@redhat.com> In-Reply-To: <20181217145548.15125-1-jferlan@redhat.com> References: <20181217145548.15125-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] tests: Return failures immediately in virErrorTestMsgs 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 17 Dec 2018 14:56:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Rather than chancing calling strchr when @err_noinfo =3D=3D NULL or calling virErrorTestMsgFormatInfoOne when @err_info =3D=3D NULL, both of which would fail, let's just return -1 immediately when we encounter an error. Signed-off-by: John Ferlan --- tests/virerrortest.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/virerrortest.c b/tests/virerrortest.c index eebf259343..48b4848b44 100644 --- a/tests/virerrortest.c +++ b/tests/virerrortest.c @@ -58,7 +58,6 @@ virErrorTestMsgs(const void *opaque ATTRIBUTE_UNUSED) const char *err_noinfo; const char *err_info; size_t i; - int ret =3D 0; =20 for (i =3D 1; i < VIR_ERR_NUMBER_LAST; i++) { err_noinfo =3D virErrorMsg(i, NULL); @@ -66,25 +65,25 @@ virErrorTestMsgs(const void *opaque ATTRIBUTE_UNUSED) =20 if (!err_noinfo) { VIR_TEST_VERBOSE("\nmissing string without info for error id %= zu\n", i); - ret =3D -1; + return -1; } =20 if (!err_info) { VIR_TEST_VERBOSE("\nmissing string with info for error id %zu\= n", i); - ret =3D -1; + return -1; } =20 if (strchr(err_noinfo, '%')) { VIR_TEST_VERBOSE("\nerror message id %zu contains formatting c= haracters: '%s'\n", i, err_noinfo); - ret =3D -1; + return -1; } =20 if (virErrorTestMsgFormatInfoOne(err_info) < 0) - ret =3D -1; + return -1; } =20 - return ret; + return 0; } =20 =20 --=20 2.17.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:07:30 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 1545058568633273.4458337303246; Mon, 17 Dec 2018 06:56:08 -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 44B0FC719C; Mon, 17 Dec 2018 14:55:57 +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 C5F0260123; Mon, 17 Dec 2018 14:55: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 1A9463F5CB; Mon, 17 Dec 2018 14:55:56 +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 wBHEtsNr009331 for ; Mon, 17 Dec 2018 09:55:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id EE0B55DA2A; Mon, 17 Dec 2018 14:55:54 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-170.phx2.redhat.com [10.3.116.170]) by smtp.corp.redhat.com (Postfix) with ESMTP id A66195ED50 for ; Mon, 17 Dec 2018 14:55:54 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 17 Dec 2018 09:55:47 -0500 Message-Id: <20181217145548.15125-3-jferlan@redhat.com> In-Reply-To: <20181217145548.15125-1-jferlan@redhat.com> References: <20181217145548.15125-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] remote: Resolve resource leak 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.39]); Mon, 17 Dec 2018 14:55:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Using a combination of VIR_ALLOC and VIR_STRDUP into a local variable and then jumping to error on the VIR_STRDUP before assiging it into the @data would cause a memory leak. Let's just avoid that by assiging directly into @data. Signed-off-by: John Ferlan --- src/remote/remote_daemon_dispatch.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 51bc055564..5cefc8480e 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -749,7 +749,6 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn, { daemonClientEventCallbackPtr callback =3D opaque; remote_domain_event_disk_change_msg data; - char **oldSrcPath_p =3D NULL, **newSrcPath_p =3D NULL; =20 if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -762,17 +761,15 @@ remoteRelayDomainEventDiskChange(virConnectPtr conn, /* build return data */ memset(&data, 0, sizeof(data)); if (oldSrcPath && - ((VIR_ALLOC(oldSrcPath_p) < 0) || - VIR_STRDUP(*oldSrcPath_p, oldSrcPath) < 0)) + ((VIR_ALLOC(data.oldSrcPath) < 0) || + VIR_STRDUP(*(data.oldSrcPath), oldSrcPath) < 0)) goto error; =20 if (newSrcPath && - ((VIR_ALLOC(newSrcPath_p) < 0) || - VIR_STRDUP(*newSrcPath_p, newSrcPath) < 0)) + ((VIR_ALLOC(data.newSrcPath) < 0) || + VIR_STRDUP(*(data.newSrcPath), newSrcPath) < 0)) goto error; =20 - data.oldSrcPath =3D oldSrcPath_p; - data.newSrcPath =3D newSrcPath_p; if (VIR_STRDUP(data.devAlias, devAlias) < 0) goto error; data.reason =3D reason; @@ -1779,7 +1776,6 @@ remoteRelayDomainQemuMonitorEvent(virConnectPtr conn, { daemonClientEventCallbackPtr callback =3D opaque; qemu_domain_monitor_event_msg data; - char **details_p =3D NULL; =20 if (callback->callbackID < 0 || !remoteRelayDomainQemuMonitorEventCheckACL(callback->client, conn, @@ -1797,10 +1793,9 @@ remoteRelayDomainQemuMonitorEvent(virConnectPtr conn, data.seconds =3D seconds; data.micros =3D micros; if (details && - ((VIR_ALLOC(details_p) < 0) || - VIR_STRDUP(*details_p, details) < 0)) + ((VIR_ALLOC(data.details) < 0) || + VIR_STRDUP(*(data.details), details) < 0)) goto error; - data.details =3D details_p; if (make_nonnull_domain(&data.dom, dom) < 0) goto error; =20 --=20 2.17.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 06:07:30 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 1545059195738924.2344098961407; Mon, 17 Dec 2018 07:06:35 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 10A2CC0270B0; Mon, 17 Dec 2018 14:56:03 +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 C77BD50415; Mon, 17 Dec 2018 14:56: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 7238F3F5D7; Mon, 17 Dec 2018 14:56: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 wBHEtwS2009353 for ; Mon, 17 Dec 2018 09:55:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 859F55D744; Mon, 17 Dec 2018 14:55:58 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-170.phx2.redhat.com [10.3.116.170]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F1632A2F3 for ; Mon, 17 Dec 2018 14:55:55 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 17 Dec 2018 09:55:48 -0500 Message-Id: <20181217145548.15125-4-jferlan@redhat.com> In-Reply-To: <20181217145548.15125-1-jferlan@redhat.com> References: <20181217145548.15125-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] remote: Handle xdr char ** data return fields more consistently 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 17 Dec 2018 14:56:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" For consistency, handle the @data "char **" (or remote_string) assignments and processing similarly between various APIs Signed-off-by: John Ferlan --- src/remote/remote_daemon_dispatch.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 5cefc8480e..fcd602304f 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1366,7 +1366,6 @@ remoteRelayDomainEventMetadataChange(virConnectPtr co= nn, { daemonClientEventCallbackPtr callback =3D opaque; remote_domain_event_callback_metadata_change_msg data; - char **nsurip; =20 if (callback->callbackID < 0 || !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) @@ -1380,13 +1379,9 @@ remoteRelayDomainEventMetadataChange(virConnectPtr c= onn, =20 data.type =3D type; if (nsuri) { - if (VIR_ALLOC(nsurip) < 0) - return -1; - if (VIR_STRDUP(*nsurip, nsuri) < 0) { - VIR_FREE(nsurip); - return -1; - } - data.nsuri =3D nsurip; + if (VIR_ALLOC(data.nsuri) < 0 || + VIR_STRDUP(*(data.nsuri), nsuri) < 0) + goto error; } =20 if (make_nonnull_domain(&data.dom, dom) < 0) @@ -1432,9 +1427,8 @@ remoteRelayDomainEventBlockThreshold(virConnectPtr co= nn, if (VIR_STRDUP(data.dev, dev) < 0) goto error; if (path) { - if (VIR_ALLOC(data.path) < 0) - goto error; - if (VIR_STRDUP(*(data.path), path) < 0) + if (VIR_ALLOC(data.path) < 0 || + VIR_STRDUP(*(data.path), path) < 0) goto error; } data.threshold =3D threshold; @@ -4006,14 +4000,9 @@ remoteDispatchNodeDeviceGetParent(virNetServerPtr se= rver ATTRIBUTE_UNUSED, ret->parentName =3D NULL; } else { /* remoteDispatchClientRequest will free this. */ - char **parent_p; - if (VIR_ALLOC(parent_p) < 0) + if (VIR_ALLOC(ret->parentName) < 0 || + VIR_STRDUP(*(ret->parentName), parent) < 0) goto cleanup; - if (VIR_STRDUP(*parent_p, parent) < 0) { - VIR_FREE(parent_p); - goto cleanup; - } - ret->parentName =3D parent_p; } =20 rv =3D 0; --=20 2.17.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list