From nobody Thu May 15 07:22:21 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1512638759043954.5531268330335; Thu, 7 Dec 2017 01:25:59 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4DA6381138; Thu, 7 Dec 2017 09:25: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 251D669281; Thu, 7 Dec 2017 09:25:57 +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 E11514BB78; Thu, 7 Dec 2017 09:25:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vB79ND6I007302 for ; Thu, 7 Dec 2017 04:23:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id A71AF183A6; Thu, 7 Dec 2017 09:23:13 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDCCB183A2; Thu, 7 Dec 2017 09:23:12 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 7 Dec 2017 10:23:00 +0100 Message-Id: <7ef514be9965327107086977ad322e7482c893b9.1512638349.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: drewwynne@gmail.com, dzamirski@datto.com Subject: [libvirt] [libvirt-php][PATCH 5/7] libvirt_domain_new: Resolve couple of memleaks 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 07 Dec 2017 09:25:57 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There are still some, but it's definitely better now. Signed-off-by: Michal Privoznik --- src/libvirt-domain.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 3c4c683..6ae6c0a 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -86,6 +86,7 @@ PHP_FUNCTION(libvirt_domain_new) HashPosition pointer; char vncl[2048] =3D { 0 }; char *xml =3D NULL; + char *hostname =3D NULL; int retval =3D 0; char uuid[VIR_UUID_STRING_BUFLEN] =3D { 0 }; zend_long flags =3D 0; @@ -149,14 +150,14 @@ PHP_FUNCTION(libvirt_domain_new) if (tmp =3D=3D NULL) { DPRINTF("%s: Cannot get installation XML\n", PHPFUNC); set_error("Cannot get installation XML" TSRMLS_CC); - RETURN_FALSE; + goto error; } =20 domain =3D virDomainDefineXML(conn->conn, tmp); if (domain =3D=3D NULL) { set_error_if_unset("Cannot define domain from the XML description"= TSRMLS_CC); DPRINTF("%s: Cannot define domain from the XML description (%s): %= s\n", PHPFUNC, LIBVIRT_G(last_error), tmp); - RETURN_FALSE; + goto error; } =20 if (virDomainCreate(domain) < 0) { @@ -178,22 +179,31 @@ PHP_FUNCTION(libvirt_domain_new) goto error; } =20 + VIR_FREE(tmp); tmp =3D get_string_from_xpath(xml, "//domain/devices/graphics[@type=3D= 'vnc']/@port", NULL, &retval); if (retval < 0) { DPRINTF("%s: Cannot get port from XML description\n", PHPFUNC); set_error_if_unset("Cannot get port from XML description" TSRMLS_C= C); goto error; } + VIR_FREE(xml); =20 - snprintf(vncl, sizeof(vncl), "%s:%s", virConnectGetHostname(conn->conn= ), tmp); + hostname =3D virConnectGetHostname(conn->conn); + if (!hostname) { + DPRINTF("%s: Cannot get hostname\n", PHPFUNC); + set_error_if_unset("Cannot get hostname" TSRMLS_CC); + goto error; + } + + snprintf(vncl, sizeof(vncl), "%s:%s", hostname, tmp); DPRINTF("%s: Trying to connect to '%s'\n", PHPFUNC, vncl); =20 #ifndef EXTWIN - if ((fd =3D connect_socket(virConnectGetHostname(conn->conn), tmp, 0, = 0, flags & DOMAIN_FLAG_TEST_LOCAL_VNC)) < 0) { + if ((fd =3D connect_socket(hostname, tmp, 0, 0, flags & DOMAIN_FLAG_TE= ST_LOCAL_VNC)) < 0) { DPRINTF("%s: Cannot connect to '%s'\n", PHPFUNC, vncl); snprintf(vncl, sizeof(vncl), "Connection failed, port %s is most l= ikely forbidden on firewall (iptables) on the host (%s)" " or the emulator VNC server is bound to localhost addres= s only.", - tmp, virConnectGetHostname(conn->conn)); + tmp, hostname); } else { close(fd); DPRINTF("%s: Connection to '%s' successfull (%s local connection)\= n", PHPFUNC, vncl, @@ -203,6 +213,7 @@ PHP_FUNCTION(libvirt_domain_new) =20 set_vnc_location(vncl TSRMLS_CC); =20 + VIR_FREE(tmp); tmp =3D installation_get_xml(conn->conn, name, memMB, maxmemMB, NULL /* arch */, uuid, vcpus, NULL, vmDisks, numDisks, vmNetworks, numNets, @@ -232,6 +243,9 @@ PHP_FUNCTION(libvirt_domain_new) resource_change_counter(INT_RESOURCE_DOMAIN, conn->conn, res_domain->d= omain, 1 TSRMLS_CC); =20 VIRT_REGISTER_RESOURCE(res_domain, le_libvirt_domain); + VIR_FREE(vmDisks); + VIR_FREE(vmNetworks); + VIR_FREE(tmp); return; =20 error: @@ -243,6 +257,9 @@ PHP_FUNCTION(libvirt_domain_new) } if (domainUpdated) virDomainFree(domainUpdated); + VIR_FREE(vmDisks); + VIR_FREE(vmNetworks); + VIR_FREE(tmp); RETURN_FALSE; } =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list