From nobody Sun Feb 8 22:06:19 2026 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