From nobody Sun May 19 06:05:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=huawei.com ARC-Seal: i=1; a=rsa-sha256; t=1662704455; cv=none; d=zohomail.com; s=zohoarc; b=PmlGf7H9Veuv3lemgga1Xcg21AXAWynxPhNguW2UvvUBoWtgxbHYF3Mf19wI7vLLc4ShLVipNRuEqBi7GONmBKu4JbKmCB7nS2+7UG4/fRWE44yHqZZlzELnWMtngL9YYTEbHotRzaHhSVb9YB65nVFsTR/7kOpBO0kmTt5DQDM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662704455; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Dvhvjd2vE/7qzVP4Hr9fb3c7smZpFs3WZ3ZnN2KMFn8=; b=ZKly6Q0PlxxZqiew44g8DvP6j45hIZtaF5OhDq2LIgx2U5GPbkd6s4t0fjHEZDy2YLY1x3B0cQ4EayaNpZur5qatEHPSy/UWIy6KHHF0BKjApvc9QFbXIlMHgkSCagQdvGMLkbX09K3voQEQ3c8FJd43G/VPAxBq3432L1bvS8M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662704455629859.4984141061749; Thu, 8 Sep 2022 23:20:55 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-549-qkc1QZZ5ONKMpsw8GY5a8A-1; Fri, 09 Sep 2022 02:20:50 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A3DA080A0B9; Fri, 9 Sep 2022 06:20:47 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC14B40B40C9; Fri, 9 Sep 2022 06:20:45 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5BD301946A44; Fri, 9 Sep 2022 06:20:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 942381946A41 for ; Fri, 9 Sep 2022 06:20:43 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 900432166B29; Fri, 9 Sep 2022 06:20:43 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast10.extmail.prod.ext.rdu2.redhat.com [10.11.55.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C69A2166B26 for ; Fri, 9 Sep 2022 06:20:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 724251C05AEE for ; Fri, 9 Sep 2022 06:20:43 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-90-kziaP_liPNCw936PCOm4WA-1; Fri, 09 Sep 2022 02:20:41 -0400 Received: from dggpeml500022.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MP5P83FGMzmVLx for ; Fri, 9 Sep 2022 14:17:00 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 9 Sep 2022 14:20:37 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662704454; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Dvhvjd2vE/7qzVP4Hr9fb3c7smZpFs3WZ3ZnN2KMFn8=; b=dVP+n0bo86KgeHG+ErrV+lbUSOZbMZmdXH8JXDvXvI/vwK4/FoohwSgQpU8ag0UnBrOFO1 DX3b/de55GvQVA2jwYZ1EPPC8fPQbjc5vYPRBBwGfiAUEHdUZCoOpRcM+FcgtvVD8pfVDx FjKDnYm7f70Qy3amOdiLLGPqdVVMI24= X-MC-Unique: qkc1QZZ5ONKMpsw8GY5a8A-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: kziaP_liPNCw936PCOm4WA-1 From: Jiacheng Jiang To: Subject: [PATCH 1/3] rpc: fix memory leak in virNetServerClientNew and virNetServerProgramDispatchCall Date: Fri, 9 Sep 2022 14:10:11 +0800 Message-ID: <20220909061013.3092350-2-jiangjiacheng@huawei.com> In-Reply-To: <20220909061013.3092350-1-jiangjiacheng@huawei.com> References: <20220909061013.3092350-1-jiangjiacheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.170] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500022.china.huawei.com (7.185.36.66) X-CFilter-Loop: Reflected X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yubihong@huawei.com, zhengchuan@huawei.com, linyilu@huawei.com, jiangjiacheng@huawei.com, xiexiangyou@huawei.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662704457190100003 Content-Type: text/plain; charset="utf-8" From: jiangjiacheng In virNetServerClientNew, client->rx is be assigned by invoking virNetServe= rClientNew, but isn't freed if client->privateData's initialization failed, which leads= to a memory leak. And in virNetServerProgramDispatchCall, the error path doesn't= free the memory of dispatcher->arg_filter, which leads to a memory leak. Signed-off-by: jiangjiacheng --- src/rpc/virnetserverclient.c | 1 + src/rpc/virnetserverprogram.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index a7d2dfa795..75df16fe96 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -443,6 +443,7 @@ virNetServerClient *virNetServerClientNew(unsigned long= long id, return NULL; =20 if (!(client->privateData =3D privNew(client, privOpaque))) { + virNetMessageFree(client->rx); virObjectUnref(client); return NULL; } diff --git a/src/rpc/virnetserverprogram.c b/src/rpc/virnetserverprogram.c index 3ddf9f0428..a813e821a3 100644 --- a/src/rpc/virnetserverprogram.c +++ b/src/rpc/virnetserverprogram.c @@ -409,11 +409,15 @@ virNetServerProgramDispatchCall(virNetServerProgram *= prog, if (virNetMessageDecodePayload(msg, dispatcher->arg_filter, arg) < 0) goto error; =20 - if (!(identity =3D virNetServerClientGetIdentity(client))) + if (!(identity =3D virNetServerClientGetIdentity(client))) { + xdr_free(dispatcher->arg_filter, arg); goto error; + } =20 - if (virIdentitySetCurrent(identity) < 0) + if (virIdentitySetCurrent(identity) < 0) { + xdr_free(dispatcher->arg_filter, arg); goto error; + } =20 /* * When the RPC handler is called: @@ -427,8 +431,10 @@ virNetServerProgramDispatchCall(virNetServerProgram *p= rog, */ rv =3D (dispatcher->func)(server, client, msg, &rerr, arg, ret); =20 - if (virIdentitySetCurrent(NULL) < 0) + if (virIdentitySetCurrent(NULL) < 0) { + xdr_free(dispatcher->arg_filter, arg); goto error; + } =20 /* * If rv =3D=3D 1, this indicates the dispatch func has --=20 2.33.0 From nobody Sun May 19 06:05:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=huawei.com ARC-Seal: i=1; a=rsa-sha256; t=1662704455; cv=none; d=zohomail.com; s=zohoarc; b=JGR7k9EQ273BgWfVQP4vhP2AHHja8zMWMCkOxvZj/tAvoohD9uzT4FbBH50UMdMpKspS8qpxeCOYQBxWtG8AxNzjL4H6nNK6yAcK+K6A5PRyCeOXe+aglUDxTJLWSkEBVlmPr/d04ooXKmZbZy5GFe6n2tuPrMIAKeP69lD/v5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662704455; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xoyqwsWbLVyj+S6YiUjNI0YpSml37K6Gaely/i8Cj0c=; b=jRodd7JDl2mhZNnS02dqagvUFhAPg9M8h3xC18nKlLjRNYcXwfEEbnz24qhdwwp/9PNMVp3z3D0BvT04vih4p+c5Q+PnTRmvMTuIKUw0aSNTXrfFUsAQo6y7P890/129lNYRsStqIX6n1nXty5yu3bqtFElI7vD/MF5HQZgBqjk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1662704455630199.21416176705998; Thu, 8 Sep 2022 23:20:55 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-542-KY33YW-nPsmcvewLhPEXZA-1; Fri, 09 Sep 2022 02:20:51 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4419811E80; Fri, 9 Sep 2022 06:20:49 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9012D4C819; Fri, 9 Sep 2022 06:20:49 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 68D3D1946A44; Fri, 9 Sep 2022 06:20:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 148551946A41 for ; Fri, 9 Sep 2022 06:20:48 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DBB32111F3B6; Fri, 9 Sep 2022 06:20:47 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D5533112131E for ; Fri, 9 Sep 2022 06:20:47 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BA0541044560 for ; Fri, 9 Sep 2022 06:20:47 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-102-_9FArtEwM4GWT6Nh0w0KcQ-1; Fri, 09 Sep 2022 02:20:45 -0400 Received: from dggpeml500022.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MP5QM1qYvznV0m for ; Fri, 9 Sep 2022 14:18:03 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 9 Sep 2022 14:20:38 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662704454; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=xoyqwsWbLVyj+S6YiUjNI0YpSml37K6Gaely/i8Cj0c=; b=hh0FkWB/rCXIVO+sAwzxFGjWurHms9pwAvbC76SDCAPsOWTnjc+7zR4zR1khFwbRryqEt+ +YYAuEez0AMSn8cP8P0z8hMxZCq8nLwnSpXNp1Ny0kFoKcGBvhUoYObfRJHM2l9t2YXAnF cgsZ4zFVM16FK/FEKLACHKSkW9sA8fU= X-MC-Unique: KY33YW-nPsmcvewLhPEXZA-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: _9FArtEwM4GWT6Nh0w0KcQ-1 From: Jiacheng Jiang To: Subject: [PATCH 2/3] qemu: fix memory leak in qemu_driver.c Date: Fri, 9 Sep 2022 14:10:12 +0800 Message-ID: <20220909061013.3092350-3-jiangjiacheng@huawei.com> In-Reply-To: <20220909061013.3092350-1-jiangjiacheng@huawei.com> References: <20220909061013.3092350-1-jiangjiacheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.170] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500022.china.huawei.com (7.185.36.66) X-CFilter-Loop: Reflected X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yubihong@huawei.com, zhengchuan@huawei.com, linyilu@huawei.com, jiangjiacheng@huawei.com, xiexiangyou@huawei.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662704457210100004 Content-Type: text/plain; charset="utf-8" From: jiangjiacheng Function virTypedParamsAddString may return -1 and the clean path doesn't free the memory of eventParams, which will lead to potential memory leak. Signed-off-by: jiangjiacheng --- src/qemu/qemu_driver.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 707f4cc1bb..c43bc4070e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4474,11 +4474,15 @@ qemuDomainPinVcpuLive(virDomainObj *vm, goto cleanup; =20 event =3D virDomainEventTunableNewFromObj(vm, eventParams, eventNparam= s); + eventParams =3D NULL; + eventNparams =3D 0; =20 ret =3D 0; =20 cleanup: virObjectEventStateQueue(driver->domainEventState, event); + if (eventParams) + virTypedParamsFree(eventParams, eventNparams); return ret; } =20 @@ -4683,6 +4687,8 @@ qemuDomainPinEmulator(virDomainPtr dom, goto endjob; =20 event =3D virDomainEventTunableNewFromDom(dom, eventParams, eventN= params); + eventParams =3D NULL; + eventNparams =3D 0; } =20 if (persistentDef) { @@ -4699,6 +4705,8 @@ qemuDomainPinEmulator(virDomainPtr dom, qemuDomainObjEndJob(vm); =20 cleanup: + if (eventParams) + virTypedParamsFree(eventParams, eventNparams); virObjectEventStateQueue(driver->domainEventState, event); virDomainObjEndAPI(&vm); return ret; @@ -5080,6 +5088,8 @@ qemuDomainPinIOThread(virDomainPtr dom, goto endjob; =20 event =3D virDomainEventTunableNewFromDom(dom, eventParams, eventN= params); + eventParams =3D NULL; + eventNparams =3D 0; } =20 if (persistentDef) { @@ -5105,6 +5115,8 @@ qemuDomainPinIOThread(virDomainPtr dom, qemuDomainObjEndJob(vm); =20 cleanup: + if (eventParams) + virTypedParamsFree(eventParams, eventNparams); virObjectEventStateQueue(driver->domainEventState, event); virDomainObjEndAPI(&vm); return ret; --=20 2.33.0 From nobody Sun May 19 06:05:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=huawei.com ARC-Seal: i=1; a=rsa-sha256; t=1662704455; cv=none; d=zohomail.com; s=zohoarc; b=W9zWze+F7lORDOF53sNQ0pbIP81set8TL62em8LeumymF7SMV4A3pUhCj9ldSqrC79UrsrzFGNcugN6C5zCqlJ+BqjH9k03zTZiC9Iw8Ziwy0Fh9xJlM16k1kXC8/EAm3MiRFvS485ux5IRMNwbOD/rM50BBIGUx0EmBAWxkdVg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662704455; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BcOxFi9VPiQzvM3wXpg1ALS4BPCZCR6WQbPKP1gTI3A=; b=SwFom/8i6FVU/PssEfDI4eDzR3IsKDfJxFJC3WZeRKGLYY11ItS4noGXrKeq0pTFh/btqnlqyTX2TAmIC/iVvK+VhQRR7yKRZuJYODevBfeXB8p56QmCeEb11iEFxy5oqJdXU+RfBG8LMq763MyvbvDN73VUey4wGnZFFZvrUdY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662704455504141.8440609966177; Thu, 8 Sep 2022 23:20:55 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-303-L_bn6lXRN_mmpLXgTvmV9w-1; Fri, 09 Sep 2022 02:20:50 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4BE41C05AFC; Fri, 9 Sep 2022 06:20:47 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90EF21415117; Fri, 9 Sep 2022 06:20:47 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1D27B1946A6F; Fri, 9 Sep 2022 06:20:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2AF621946A41 for ; Fri, 9 Sep 2022 06:20:45 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 200CC2026D64; Fri, 9 Sep 2022 06:20:45 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast10.extmail.prod.ext.rdu2.redhat.com [10.11.55.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1C1622026D4C for ; Fri, 9 Sep 2022 06:20:45 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 013631C05AE6 for ; Fri, 9 Sep 2022 06:20:45 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-524-parixel9OHSAEs-xoXhkXQ-1; Fri, 09 Sep 2022 02:20:43 -0400 Received: from dggpeml500022.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MP5PB2rmSzmVB0 for ; Fri, 9 Sep 2022 14:17:02 +0800 (CST) Received: from localhost.localdomain (10.175.104.170) by dggpeml500022.china.huawei.com (7.185.36.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 9 Sep 2022 14:20:39 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662704454; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=BcOxFi9VPiQzvM3wXpg1ALS4BPCZCR6WQbPKP1gTI3A=; b=fNe/VukJX4ozLD+CeRiQVUQMDGi4tqXFVLDWSrcH11KaIcF7ZqHqfDJ0uI+HI0B+Ux7pNo WT7wc0sVrrF7vgEUGHECK7UueUQrKIPspGCjUZoKCMYF4eGjgJScABOAJUHn2Une6N1qr8 9lcuowH5k2Hdg0v9j1HflGRtAG8OmuA= X-MC-Unique: L_bn6lXRN_mmpLXgTvmV9w-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: parixel9OHSAEs-xoXhkXQ-1 From: Jiacheng Jiang To: Subject: [PATCH 3/3] qemu: Fix memory leak fix memory leak in the condition of attaching cdrom Date: Fri, 9 Sep 2022 14:10:13 +0800 Message-ID: <20220909061013.3092350-4-jiangjiacheng@huawei.com> In-Reply-To: <20220909061013.3092350-1-jiangjiacheng@huawei.com> References: <20220909061013.3092350-1-jiangjiacheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.170] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500022.china.huawei.com (7.185.36.66) X-CFilter-Loop: Reflected X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yubihong@huawei.com, zhengchuan@huawei.com, linyilu@huawei.com, jiangjiacheng@huawei.com, xiexiangyou@huawei.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662704456996100001 Content-Type: text/plain; charset="utf-8" From: jiangjiacheng The qemuDomainAttachDeviceLive interface is invoked for attaching cdrom in the same way as common disks. The difference is that attach cdrom only upda= te the src of the original device while common disk will add new disk to vm's device list. Therefore, the dev->data.disk should be freed to avoid memory = leak when attach cdrom as well as floppy. Signed-off-by: jiangjiacheng --- src/qemu/qemu_driver.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c43bc4070e..64b1ca3f39 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6882,6 +6882,9 @@ qemuDomainAttachDeviceLive(virDomainObj *vm, ret =3D qemuDomainAttachDeviceDiskLive(driver, vm, dev); if (!ret) { alias =3D dev->data.disk->info.alias; + if ((virDomainDiskDevice)dev->data.disk->device =3D=3D VIR_DOM= AIN_DISK_DEVICE_CDROM || + (virDomainDiskDevice)dev->data.disk->device =3D=3D VIR_DOM= AIN_DISK_DEVICE_FLOPPY) + virDomainDiskDefFree(dev->data.disk); dev->data.disk =3D NULL; } break; --=20 2.33.0