From: Leif Lindholm <leif.lindholm@linaro.org>
To: Jian J Wang <jian.j.wang@intel.com>
Cc: edk2-devel@lists.01.org, Star Zeng <star.zeng@intel.com>,
Jiewen Yao <jiewen.yao@intel.com>, Ruiyu Ni <ruiyu.ni@intel.com>
Subject: Re: [PATCH v3 1/2] MdeModulePkg/Core: fill logic hole in MemoryProtectionCpuArchProtocolNotify
Date: Wed, 7 Nov 2018 07:52:32 +0000 [thread overview]
Message-ID: <20181107075231.f5nv6dwsvfumys4r@bivouac.eciton.net> (raw)
In-Reply-To: <20181107071248.6340-2-jian.j.wang@intel.com>
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.
No objection to the content, but comments not intended to be committed
should go in the cover letter or below the ---.
A changelog between revisions is best kept in the cover letter,
including all changes in reverse chronological order, like:
Changes since v2:
- ...
Changes since v1:
- ...
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.
(I won't give a reviewed-by since I have only been commenting on
style, not functionality.)
/
Leif
> 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 = 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 <star.zeng@intel.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Leif Lindholm <leif.lindholm@linaro.org>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
> ---
> 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 = CoreLocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&gCpu);
> if (EFI_ERROR (Status)) {
> - return;
> + goto Done;
> }
>
> //
> @@ -991,7 +991,7 @@ MemoryProtectionCpuArchProtocolNotify (
> HeapGuardCpuArchProtocolNotify ();
>
> if (mImageProtectionPolicy == 0) {
> - return;
> + goto Done;
> }
>
> Status = gBS->LocateHandleBuffer (
> @@ -1002,7 +1002,7 @@ MemoryProtectionCpuArchProtocolNotify (
> &HandleBuffer
> );
> if (EFI_ERROR (Status) && (NoHandles == 0)) {
> - return ;
> + goto Done;
> }
>
> for (Index = 0; Index < NoHandles; Index++) {
> @@ -1025,9 +1025,10 @@ MemoryProtectionCpuArchProtocolNotify (
>
> ProtectUefiImage (LoadedImage, LoadedImageDevicePath);
> }
> + FreePool (HandleBuffer);
>
> +Done:
> CoreCloseEvent (Event);
> - return;
> }
>
> /**
> --
> 2.16.2.windows.1
>
next prev parent reply other threads:[~2018-11-07 7:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-07 7:12 [PATCH v3 0/2] fix ineffective guard page issue Jian J Wang
2018-11-07 7:12 ` [PATCH v3 1/2] MdeModulePkg/Core: fill logic hole in MemoryProtectionCpuArchProtocolNotify Jian J Wang
2018-11-07 7:52 ` Leif Lindholm [this message]
2018-11-07 8:33 ` Wang, Jian J
2018-11-07 7:12 ` [PATCH v3 2/2] MdeModulePkg/Core: fix ineffective guard page issue Jian J Wang
2018-11-07 7:22 ` [PATCH v3 0/2] " Zeng, Star
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181107075231.f5nv6dwsvfumys4r@bivouac.eciton.net \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox