From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 365732118C511 for ; Wed, 7 Nov 2018 00:33:25 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Nov 2018 00:33:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,475,1534834800"; d="scan'208";a="106589798" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga002.jf.intel.com with ESMTP; 07 Nov 2018 00:33:25 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 7 Nov 2018 00:33:24 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.161]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.214]) with mapi id 14.03.0415.000; Wed, 7 Nov 2018 16:33:22 +0800 From: "Wang, Jian J" To: Leif Lindholm CC: "edk2-devel@lists.01.org" , "Zeng, Star" , "Yao, Jiewen" , "Ni, Ruiyu" Thread-Topic: [PATCH v3 1/2] MdeModulePkg/Core: fill logic hole in MemoryProtectionCpuArchProtocolNotify Thread-Index: AQHUdm7c4WZPCDucFkWlSiKl0W3Vz6VD+9bw Date: Wed, 7 Nov 2018 08:33:22 +0000 Message-ID: References: <20181107071248.6340-1-jian.j.wang@intel.com> <20181107071248.6340-2-jian.j.wang@intel.com> <20181107075231.f5nv6dwsvfumys4r@bivouac.eciton.net> In-Reply-To: <20181107075231.f5nv6dwsvfumys4r@bivouac.eciton.net> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNjUxMzRhZWQtM2MwYi00ODk5LWI3OGEtMWFlMGJmOGRiMzZjIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoibE1EVjlTcnBXdmhuXC9SRmtJSERQSTRKNGpnb0ZkTHRJS3RFVXhvWnFuNzNMYWNhMElHbTBXUktvM0FmcjRRM0UifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v3 1/2] MdeModulePkg/Core: fill logic hole in MemoryProtectionCpuArchProtocolNotify X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Nov 2018 08:33:26 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Leif, Thanks for the comments. I'll push the patch after removing the change log from the commit log. Regards, Jian > -----Original Message----- > From: Leif Lindholm [mailto:leif.lindholm@linaro.org] > Sent: Wednesday, November 07, 2018 3:53 PM > To: Wang, Jian J > Cc: edk2-devel@lists.01.org; Zeng, Star ; Yao, Jiewe= n > ; Ni, Ruiyu > Subject: Re: [PATCH v3 1/2] MdeModulePkg/Core: fill logic hole in > MemoryProtectionCpuArchProtocolNotify >=20 >=20 > On Wed, Nov 07, 2018 at 03:12:47PM +0800, Jian J Wang wrote: > > > v3: fixed one more memory leak in the same function and updated > > > commit message accordingly. >=20 > No objection to the content, but comments not intended to be committed > should go in the cover letter or below the ---. >=20 > A changelog between revisions is best kept in the cover letter, > including all changes in reverse chronological order, like: >=20 > Changes since v2: > - ... >=20 > Changes since v1: > - ... >=20 > I expect whoever pushes the patches will edit the history out of the > commit message, but putting it in the cover-letter means less work for > them. >=20 > (I won't give a reviewed-by since I have only been commenting on > style, not functionality.) >=20 > / > Leif >=20 > > At the end of of MemoryProtectionCpuArchProtocolNotify there's cleanup > > code to free resource. But at line 978, 994, 1005 the function returns > > directly. This patch use "goto" to replace "return" to make sure the > > resource is freed before exit. > > > > 1029: CoreCloseEvent (Event); > > 1030: return; > > > > There's another memory leak after calling gBS->LocateHandleBuffer() in > > the same function: > > > > Status =3D gBS->LocateHandleBuffer ( > > ByProtocol, > > &gEfiLoadedImageProtocolGuid, > > NULL, > > &NoHandles, > > &HandleBuffer > > ); > > > > HandleBuffer is allocated in above call but never freed. This patch > > will also add code to free it. > > > > Cc: Star Zeng > > Cc: Jiewen Yao > > Cc: Ruiyu Ni > > Cc: Leif Lindholm > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Jian J Wang > > --- > > MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 9 +++++---- > > 1 file changed, 5 insertions(+), 4 deletions(-) > > > > diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c > b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c > > index 6298b67db1..8a93c5362a 100644 > > --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c > > +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c > > @@ -975,7 +975,7 @@ MemoryProtectionCpuArchProtocolNotify ( > > DEBUG ((DEBUG_INFO, "MemoryProtectionCpuArchProtocolNotify:\n")); > > Status =3D CoreLocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID > **)&gCpu); > > if (EFI_ERROR (Status)) { > > - return; > > + goto Done; > > } > > > > // > > @@ -991,7 +991,7 @@ MemoryProtectionCpuArchProtocolNotify ( > > HeapGuardCpuArchProtocolNotify (); > > > > if (mImageProtectionPolicy =3D=3D 0) { > > - return; > > + goto Done; > > } > > > > Status =3D gBS->LocateHandleBuffer ( > > @@ -1002,7 +1002,7 @@ MemoryProtectionCpuArchProtocolNotify ( > > &HandleBuffer > > ); > > if (EFI_ERROR (Status) && (NoHandles =3D=3D 0)) { > > - return ; > > + goto Done; > > } > > > > for (Index =3D 0; Index < NoHandles; Index++) { > > @@ -1025,9 +1025,10 @@ MemoryProtectionCpuArchProtocolNotify ( > > > > ProtectUefiImage (LoadedImage, LoadedImageDevicePath); > > } > > + FreePool (HandleBuffer); > > > > +Done: > > CoreCloseEvent (Event); > > - return; > > } > > > > /** > > -- > > 2.16.2.windows.1 > >