From nobody Thu May 15 03:30:06 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 1515500506232331.81526509646585; Tue, 9 Jan 2018 04:21:46 -0800 (PST) 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 9582683F47; Tue, 9 Jan 2018 12:21:44 +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 356625D9C8; Tue, 9 Jan 2018 12:21:44 +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 2DF3E18033D9; Tue, 9 Jan 2018 12:21:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w09CLgbQ005165 for ; Tue, 9 Jan 2018 07:21:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0E126600C2; Tue, 9 Jan 2018 12:21:42 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0896E63F94 for ; Tue, 9 Jan 2018 12:21:39 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DC6ADC01F296 for ; Tue, 9 Jan 2018 12:21:38 +0000 (UTC) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3354CADDE for ; Tue, 9 Jan 2018 12:21:37 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Adam Majer To: libvir-list@redhat.com Date: Tue, 9 Jan 2018 13:20:38 +0100 Message-Id: <20180109122038.20938-3-amajer@suse.de> In-Reply-To: <20180109122038.20938-1-amajer@suse.de> References: <20180109122038.20938-1-amajer@suse.de> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 09 Jan 2018 12:21:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 09 Jan 2018 12:21:39 +0000 (UTC) for IP:'195.135.220.15' DOMAIN:'mx2.suse.de' HELO:'mx2.suse.de' FROM:'amajer@suse.de' RCPT:'' X-RedHat-Spam-Score: -2.311 (RCVD_IN_DNSWL_MED, SPF_PASS, T_RP_MATCHES_RCVD) 195.135.220.15 mx2.suse.de 195.135.220.15 mx2.suse.de X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Adam Majer Subject: [libvirt] [PATCH 2/2] Fix memory leak in set_input_props 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.27]); Tue, 09 Jan 2018 12:21:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When caption is specified, cap was allocated and assigned a new pointer while the old never freed. Free cap before replacing it. get_input_dev_caption only returns valid cap pointer on success, so do not try to free it on failure. Signed-off-by: Adam Majer --- src/Virt_SettingsDefineCapabilities.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Virt_SettingsDefineCapabilities.c b/src/Virt_SettingsDefin= eCapabilities.c index 85cb27a..0a1d61e 100644 --- a/src/Virt_SettingsDefineCapabilities.c +++ b/src/Virt_SettingsDefineCapabilities.c @@ -1978,9 +1978,9 @@ static CMPIStatus set_input_props(const CMPIObjectPat= h *ref, CMPIStatus s =3D {CMPI_RC_OK, NULL}; CMPIInstance *inst; char *cap; + char *tmp; =20 if (get_input_dev_caption(type, bus, &cap) !=3D 1) { - free(cap); cu_statusf(_BROKER, &s, CMPI_RC_ERR_NOT_FOUND, "Unable to build input caption"); @@ -1988,12 +1988,14 @@ static CMPIStatus set_input_props(const CMPIObjectP= ath *ref, } =20 if (caption !=3D NULL) { - if (asprintf(&cap, "%s %s", caption, cap) =3D=3D -1) { + if (asprintf(&tmp, "%s %s", caption, cap) =3D=3D -1) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_NOT_FOUND, "Unable to build input caption"); goto out; } + free(cap); + cap =3D tmp; } =20 inst =3D sdc_rasd_inst(&s, ref, CIM_RES_TYPE_INPUT, DEVICE_RASD); --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list