From nobody Thu Nov 28 08:34:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=outlook.com); dmarc=pass(p=none dis=none) header.from=outlook.com ARC-Seal: i=2; a=rsa-sha256; t=1692846237; cv=pass; d=zohomail.com; s=zohoarc; b=VU08m3FbDbyEvNXPL7D3ifVLmRHVbies+Pchf9WBDNwoVJD5QtBylNPF0n1/vv3Ure3aBaGeXw8uIynNPkSpRwFTjuUZ1iaDKgNzyG7wau+RGnyMQkeYMri32dcg9EvRH8m8UHM5N1QzgCIAQiRvmFUdM2Ok9aKtdPjsrENmZxA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692846237; 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=PFOUqukZvxLdb6XYjaya2cgQnJ3JaxU51P/0kDvPROw=; b=ekWmZGiYMXKZr2mIRrU4K9iHQUCDGMMk1BqwQTVBV5o3HZ/UiWBVBBv1lLpbjjoTbY5iI73zdC4vKo2B+q90R3AZivtElmWfY+sSegzKHx0TAEZ5e5J3cHYVUT1S0xaXQnjghGpm+RIPLnaBTAPb6nRAPzRAyoZnFA9WM0c6A2E= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=outlook.com); dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692846237837200.4846541208725; Wed, 23 Aug 2023 20:03:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qZ0co-0002s9-PZ; Wed, 23 Aug 2023 23:03:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qZ0cn-0002s1-MB for qemu-devel@nongnu.org; Wed, 23 Aug 2023 23:03:09 -0400 Received: from mail-dm6nam04olkn20801.outbound.protection.outlook.com ([2a01:111:f400:7e8b::801] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qZ0ck-0005Iv-US for qemu-devel@nongnu.org; Wed, 23 Aug 2023 23:03:09 -0400 Received: from SA1PR11MB6760.namprd11.prod.outlook.com (2603:10b6:806:25f::14) by PH8PR11MB7990.namprd11.prod.outlook.com (2603:10b6:510:259::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.24; Thu, 24 Aug 2023 03:03:01 +0000 Received: from SA1PR11MB6760.namprd11.prod.outlook.com ([fe80::df85:2db:d56b:38bf]) by SA1PR11MB6760.namprd11.prod.outlook.com ([fe80::df85:2db:d56b:38bf%5]) with mapi id 15.20.6699.020; Thu, 24 Aug 2023 03:03:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dIjZ+AYXIrHJZtYG5hwSYCY0iucnKG1ynZi3AglhYJWIloMrkzcJjVfMHg6ica2Mnl/Jgih9wHAvxi0K2t2EVPmnayAZIGgCAO8qHDtpFDW3IoQaiY0OJ6VZpOJHdqcY80h2vAHh2ZmraHzi0S6rAWOt6XjlAuH3Xa8sHWfFpEkWcC2FYRT0jaeGzxGHKV6ERKsQyUJgJ5c2unCKaZRnNmN/j2508GvRDsw22CCBZ1SoKAPveRhC88qpXLBM/JOP8RbaKYe+V+gwaHUaVMtHLkVmsYScjiMWAOkOqPe2si2njR6knqSiY12pY9skqVr9shJLEqSaeJOY2YrOwxBAQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PFOUqukZvxLdb6XYjaya2cgQnJ3JaxU51P/0kDvPROw=; b=g56VLJLUgJfpw1AFa5fzVoL0w3eIJ3p1b4GtjW35KWoDkwPsYtbjY7tE7NbhfaZfqShqy71/qAkB7HuBUafZGXYH4FFf6Hec0zlKqe42lqVhzDm22LbjJIz9Q/KDKC0YQJZKPUeNSU1KiEV48rR1vbpZstD3A+bCh5oTDvTrk+CjZKS+3codQlzehNQtE8ddW8OPma8iLeiiarmVq6ln/w/TEdW6NkLXcSUuhg7I55oVXgoU5EyLNs+FIA9PQcOv4a+HwyNtKzNozuOLnuj9Wf5Xt3EDMrRauRTZa7ePkV0AOn+U8G3ys1hg+QPhowvvjTfXF32zuUb8PyDxoP5hBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PFOUqukZvxLdb6XYjaya2cgQnJ3JaxU51P/0kDvPROw=; b=FEpViZc0GTsSUg2j8rx0eIdGnG7coMnn3x0DlGP2frGQ1+htObqLN3PovW6dhwR2d0XUllIEliSVM5KGXx7kLn85Bt8855eT7O9oGHugEXCkOc791jbrXpiRld1w6/rj194+74Hq8Kk+5KZ6L0cUt3VOLMv82LBYz466tyPMejptSBaxSW7E8ssEU6oQzxb+1Qawq4pLm4KPC4+D4GG6Y9Bs6rrj5n5vfCG6x6eawR9o4/vYsgsAYNWGwi7G/UiICs+2KFGoeCIyGn3u7wnkjqYvutBGThfnUv2A5tjDvQBACcbITxJMl9kZjZNS9GYHy+tyPLdtTa+HEQ96I5JEjg== From: =?utf-8?B?6ZizIOaYpeWFiQ==?= To: Yong Huang CC: "qemu-devel@nongnu.org" Subject: =?utf-8?B?5Zue5aSNOiBbUEFUQ0hdIHNvZnRtbXU6IEZpeCBkaXJ0eWxpbWl0IG1lbW9y?= =?utf-8?Q?y_leak?= Thread-Topic: [PATCH] softmmu: Fix dirtylimit memory leak Thread-Index: AQHZ1ZYqxLXBulDR0Em6IsmTVnEoZq/4mW+AgAAqODE= Date: Thu, 24 Aug 2023 03:03:01 +0000 Message-ID: References: In-Reply-To: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: x-tmn: [7WhzkQGOpT6OqvdzRSka5sOrYv8RWZks/LmBFriqhAw=] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: SA1PR11MB6760:EE_|PH8PR11MB7990:EE_ x-ms-office365-filtering-correlation-id: a47bd6c7-a0cc-4255-1aee-08dba44ea0b8 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: A0cxYvnCLbrI0xQKhBH0nB7HQ/1Rvxe5xg2lQN6/9kK1lyo23kbXTKIzf1r99VcVobAGjbku8wwCEPokuMwiqG6RiUckLkVQWPaAaFuDT/r5IIoyMcUudzlwwerOLqxdZC0A0DRLchGj/zkSdvImvYgKgALNRPfvDq77NRw4ba3mOQevI2a5Q1uHxGfv3Y3kf4+rOSSoI6mZ6ObU1dYFHWwJEA/WILXz+6XXXvuLsTK0qrxJC+hLbqg5sCkMIROIbBNf+ISkRTaEnw6xgGQaAguxv1E5uG562GKeX4AQvHgiY24k5Gw9gEfrNmj0d+NIuvu+tfSa56rvwGMCKYI0FNCY03022XO0F+gR5U/DMW742V2GDUexZtP0p7kB0k99gusWYiB0upqTzllOfirDqEZP/FZGHBGan1sq6zmQur3JfsBtNERMKblxE/0ox2TmNZ7IoAv/DGoEzkMp8RiFsB45qV82/sdhroQB9C2ues76uCujRY1cL/Wezwp0yTaU0GgrkkfxYOEWrlMW5ozxM5cT6cWDoaA+9HQd1t6Gu9EjqA+i1CQvDkz4KUYYCklR x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?B?azAwZFI4RTRmaXhORy81SUpSMG93S3FmSSt0cFZjOW1DOGZRWTBjUjJMNHF2?= =?utf-8?B?bzM1cHFxWmJIMjNTVW42eWFrSW5MSDhKS0lDc3BnL0g3aDl5MERoQ0I1TWRJ?= =?utf-8?B?UWdGcE56WkRKSXdCYnZPS1ZhQTdacis3RjlJREc2SW52TFVrVldmQitsaGlJ?= =?utf-8?B?SWtXTTJETTB4R0I0WmVvVWVNQWxHaG9mRUFuS29UVjNWbzlHUG9kVmN5cmQ3?= =?utf-8?B?UDMyNWQ3VVltUHkvei96WStKbGJuUXNTWjlPSEIvR3QwUy9NOWhNTkd3ZWhi?= =?utf-8?B?WC84dVFrZTFUSk1iTjNqd2luK09mNkMrNXZ2NFpQdW1pTXBnYnQxS2VCalJY?= =?utf-8?B?QVhkZUdGU1JrVXUzTFIvRFZ1NVFrQ3h5TXpZeTN5QU5ueVkzUFMzTi82SWJh?= =?utf-8?B?cmVuamU4bStHOUxPaEV2Rm85dmYwbUtSblc4MlFXRGRNSkdhRGE1WTAwc2po?= =?utf-8?B?S001aHVVWVAzZEtLejNnZFBXU2t3WTBTNkF1MzFNSnB1bktDVkNQYXRjbzRr?= =?utf-8?B?cUdiM3lBdEd5UnphNDBuOGpWd1FtYVNqVEIzTHhJZmRxOC94MCtObXJhejQ5?= =?utf-8?B?NEhKZTlqZzc0YWFXK1g5UzBrWDJWWEdQM2Q4R3I2d3h5R0NPL24wZjFLdHNz?= =?utf-8?B?RGRabXNuR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zeG1FTE9jWnpw?= =?utf-8?B?RWpOUUdrbDZsNEMzbGo0QThpR1RVVzFGRUwwcGpNbWU1bEZvbTFMTGprajBv?= =?utf-8?B?OXNkaC9HcHdXUndhemVBV2tMYnMwQkE9PQ==?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SA1PR11MB6760.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: a47bd6c7-a0cc-4255-1aee-08dba44ea0b8 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Aug 2023 03:03:01.3802 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR11MB7990 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a01:111:f400:7e8b::801; envelope-from=alloc.young@outlook.com; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @outlook.com) X-ZM-MESSAGEID: 1692846239415100001 ________________________________________ =E5=8F=91=E4=BB=B6=E4=BA=BA: Yong Huang =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2023=E5=B9=B48=E6=9C=8824=E6=97=A5 8:= 31 =E6=94=B6=E4=BB=B6=E4=BA=BA: alloc.young@outlook.com =E6=8A=84=E9=80=81: qemu-devel@nongnu.org =E4=B8=BB=E9=A2=98: Re: [PATCH] softmmu: Fix dirtylimit memory leak On Wed, Aug 23, 2023 at 3:48=E2=80=AFPM > wrote: From: "alloc.young" > Fix memory leak in hmp_info_vcpu_dirty_limit,use g_autoptr handle memory deallocation, alse use g_free to match g_malloc && g_new functions. Signed-off-by: alloc.young > Reviewed-by: Hyman Huang(=E9=BB=84=E5=8B=87) > --- softmmu/dirtylimit.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) [...] diff --git a/softmmu/dirtylimit.c b/softmmu/dirtylimit.c index 3c275ee55b..fa959d7743 100644 --- a/softmmu/dirtylimit.c +++ b/softmmu/dirtylimit.c @@ -100,7 +100,7 @@ static void vcpu_dirty_rate_stat_collect(void) stat.rates[i].dirty_rate; } - free(stat.rates); + g_free(stat.rates); } Code optimization. static void *vcpu_dirty_rate_stat_thread(void *opaque) @@ -171,10 +171,10 @@ void vcpu_dirty_rate_stat_initialize(void) void vcpu_dirty_rate_stat_finalize(void) { - free(vcpu_dirty_rate_stat->stat.rates); + g_free(vcpu_dirty_rate_stat->stat.rates); vcpu_dirty_rate_stat->stat.rates =3D NULL; - free(vcpu_dirty_rate_stat); + g_free(vcpu_dirty_rate_stat); vcpu_dirty_rate_stat =3D NULL; } Likewise... @@ -220,10 +220,10 @@ void dirtylimit_state_initialize(void) void dirtylimit_state_finalize(void) { - free(dirtylimit_state->states); + g_free(dirtylimit_state->states); dirtylimit_state->states =3D NULL; - free(dirtylimit_state); + g_free(dirtylimit_state); dirtylimit_state =3D NULL; Likewise... trace_dirtylimit_state_finalize(); @@ -653,7 +653,8 @@ struct DirtyLimitInfoList *qmp_query_vcpu_dirty_limit(E= rror **errp) void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict) { - DirtyLimitInfoList *limit, *head, *info =3D NULL; + DirtyLimitInfoList *info; + g_autoptr(DirtyLimitInfoList) head =3D NULL; Error *err =3D NULL; if (!dirtylimit_in_service()) { @@ -661,20 +662,17 @@ void hmp_info_vcpu_dirty_limit(Monitor *mon, const QD= ict *qdict) return; } - info =3D qmp_query_vcpu_dirty_limit(&err); + head =3D qmp_query_vcpu_dirty_limit(&err); if (err) { hmp_handle_error(mon, err); return; } - head =3D info; - for (limit =3D head; limit !=3D NULL; limit =3D limit->next) { + for (info =3D head; info !=3D NULL; info =3D info->next) { monitor_printf(mon, "vcpu[%"PRIi64"], limit rate %"PRIi64 " (MB/s)= ," " current rate %"PRIi64 " (MB/s)\n", - limit->value->cpu_index, - limit->value->limit_rate, - limit->value->current_rate); + info->value->cpu_index, + info->value->limit_rate, + info->value->current_rate); } - - g_free(info); Fix memory leak. } -- 2.39.3 I'll choose the memory leak modifications to keep the patch focused on a si= ngle independent issue. Ok, will send a patch just to fix this issue, thx Anyway, Reviewed-by: Hyman Huang(=E9=BB=84=E5=8B=87) > -- Best regards