From nobody Sat Apr 27 06:31:18 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.zoho.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 1497424118319863.7166385342415; Wed, 14 Jun 2017 00:08:38 -0700 (PDT) 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 5E69B61B85; Wed, 14 Jun 2017 07:08:36 +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 A14588A6EE; Wed, 14 Jun 2017 07:08:35 +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 C0CC11841C50; Wed, 14 Jun 2017 07:08:34 +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 v5E78XPB023500 for ; Wed, 14 Jun 2017 03:08:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8266F8D6B5; Wed, 14 Jun 2017 07:08:33 +0000 (UTC) Received: from beluga.usersys.redhat.com (unknown [10.43.2.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id D8D658D6BB; Wed, 14 Jun 2017 07:08:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5E69B61B85 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5E69B61B85 From: Erik Skultety To: libvir-list@redhat.com Date: Wed, 14 Jun 2017 09:10:15 +0200 Message-Id: <7f52dd0388a257b65aa161b9fd03aaadd943a20e.1497424104.git.eskultet@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2] qemu: monitor: Fix a memory leak in qemuMonitorJSONAttachCharDevCommand 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 14 Jun 2017 07:08:37 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" With the current logic, we only free @tlsalias as part of the error label and would have to free it explicitly earlier in the code. Convert the error label to cleanup, so that we have only one sink, where we handle all frees. Since since JSON object append operation consumes pointers, make sure @backend is cleared before we hit the cleanup label. Signed-off-by: Erik Skultety --- src/qemu/qemu_monitor_json.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index f208dd05a..5ddc09ca6 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6430,8 +6430,8 @@ static virJSONValuePtr qemuMonitorJSONAttachCharDevCommand(const char *chrID, const virDomainChrSourceDef *chr) { - virJSONValuePtr ret; - virJSONValuePtr backend; + virJSONValuePtr ret =3D NULL; + virJSONValuePtr backend =3D NULL; virJSONValuePtr data =3D NULL; virJSONValuePtr addr =3D NULL; const char *backend_type =3D NULL; @@ -6440,7 +6440,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, =20 if (!(backend =3D virJSONValueNewObject()) || !(data =3D virJSONValueNewObject())) { - goto error; + goto cleanup; } =20 switch ((virDomainChrType) chr->type) { @@ -6456,14 +6456,14 @@ qemuMonitorJSONAttachCharDevCommand(const char *chr= ID, case VIR_DOMAIN_CHR_TYPE_FILE: backend_type =3D "file"; if (virJSONValueObjectAppendString(data, "out", chr->data.file.pat= h) < 0) - goto error; + goto cleanup; break; =20 case VIR_DOMAIN_CHR_TYPE_DEV: backend_type =3D STRPREFIX(chrID, "parallel") ? "parallel" : "seri= al"; if (virJSONValueObjectAppendString(data, "device", chr->data.file.path) < 0) - goto error; + goto cleanup; break; =20 case VIR_DOMAIN_CHR_TYPE_TCP: @@ -6472,7 +6472,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, chr->data.tcp.service= ); if (!addr || virJSONValueObjectAppend(data, "addr", addr) < 0) - goto error; + goto cleanup; addr =3D NULL; =20 telnet =3D chr->data.tcp.protocol =3D=3D VIR_DOMAIN_CHR_TCP_PROTOC= OL_TELNET; @@ -6480,13 +6480,13 @@ qemuMonitorJSONAttachCharDevCommand(const char *chr= ID, if (virJSONValueObjectAppendBoolean(data, "wait", false) < 0 || virJSONValueObjectAppendBoolean(data, "telnet", telnet) < 0 || virJSONValueObjectAppendBoolean(data, "server", chr->data.tcp.= listen) < 0) - goto error; + goto cleanup; if (chr->data.tcp.tlscreds) { if (!(tlsalias =3D qemuAliasTLSObjFromSrcAlias(chrID))) - goto error; + goto cleanup; =20 if (virJSONValueObjectAppendString(data, "tls-creds", tlsalias= ) < 0) - goto error; + goto cleanup; } break; =20 @@ -6496,14 +6496,14 @@ qemuMonitorJSONAttachCharDevCommand(const char *chr= ID, chr->data.udp.connect= Service); if (!addr || virJSONValueObjectAppend(data, "remote", addr) < 0) - goto error; + goto cleanup; =20 if (chr->data.udp.bindHost) { addr =3D qemuMonitorJSONBuildInetSocketAddress(chr->data.udp.b= indHost, chr->data.udp.bin= dService); if (!addr || virJSONValueObjectAppend(data, "local", addr) < 0) - goto error; + goto cleanup; } addr =3D NULL; break; @@ -6514,12 +6514,12 @@ qemuMonitorJSONAttachCharDevCommand(const char *chr= ID, =20 if (!addr || virJSONValueObjectAppend(data, "addr", addr) < 0) - goto error; + goto cleanup; addr =3D NULL; =20 if (virJSONValueObjectAppendBoolean(data, "wait", false) < 0 || virJSONValueObjectAppendBoolean(data, "server", chr->data.nix.= listen) < 0) - goto error; + goto cleanup; break; =20 case VIR_DOMAIN_CHR_TYPE_SPICEVMC: @@ -6527,7 +6527,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, =20 if (virJSONValueObjectAppendString(data, "type", virDomainChrSpicevmcTypeToStrin= g(chr->data.spicevmc)) < 0) - goto error; + goto cleanup; break; =20 case VIR_DOMAIN_CHR_TYPE_SPICEPORT: @@ -6544,28 +6544,27 @@ qemuMonitorJSONAttachCharDevCommand(const char *chr= ID, _("Hotplug unsupported for char device type '%d= '"), chr->type); } - goto error; + goto cleanup; } =20 if (virJSONValueObjectAppendString(backend, "type", backend_type) < 0 = || virJSONValueObjectAppend(backend, "data", data) < 0) - goto error; + goto cleanup; data =3D NULL; =20 if (!(ret =3D qemuMonitorJSONMakeCommand("chardev-add", "s:id", chrID, "a:backend", backend, NULL))) - goto error; + goto cleanup; + backend =3D NULL; =20 - return ret; - - error: + cleanup: VIR_FREE(tlsalias); virJSONValueFree(addr); virJSONValueFree(data); virJSONValueFree(backend); - return NULL; + return ret; } =20 =20 --=20 2.13.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list