From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::342; helo=mail-wm1-x342.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C003F2118847D for ; Tue, 6 Nov 2018 23:52:36 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id f2-v6so1131926wme.3 for ; Tue, 06 Nov 2018 23:52:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Z0OAgtybYz5SWIFaV/Q2UCWDFuN7ofXH4TU/qdPtQ+U=; b=e5AZ94+jFI8vs292z9uqVBWDf3BDU0ewFoDLYXRpAP9eU3V5kl/scBcoN6wh8tlZao rHFfE98ZK0+wyfxbtIRCeKuuBuGU10DX1zclkQvtG1oyVs/Isqojfxuk4czps3DhhsDc b7fxGA1uvOzCunL77vGoESccX+0gIxePfFVYM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Z0OAgtybYz5SWIFaV/Q2UCWDFuN7ofXH4TU/qdPtQ+U=; b=Cf1KuOIuWJKkQizrpjvVDQi9UnSlN6/dWPVzvjOYZbeTtgNewqkMDwTjAKAiczU/yD 7XO7EU7Hw6li6s9n3K0l+oWHpP+CCpneBXGIJey+O+vSuZCIY65CG5J2dajKprWjORh0 gIy6PLnReMTNSGnEhVulrzgi9Ap8A4GPHALIU33Y+ZaMcKpKiexBAewhZFTaMvw4uOBE FAbmxp236KOz6DI1yym+akivgg9FQZFoIhrjt7JjDC74J6IlDPr0MMntHdC4sl4EN0Nr RzAMStfM+ZVnteTkNngTm7D9j2pIvj5yk5vYa+udVRGOsD34QZhE03ur4bDm7gnu3nit oowQ== X-Gm-Message-State: AGRZ1gLlIROEcSmfeAB/dZqK7F0SbA6zQB+AznI4ASe5afKjSe6R+iJM xrY1e4vjQ8gPgOhB5M5p+3a1QQ== X-Google-Smtp-Source: AJdET5dtMPyaE25mAN/VRpjPFjBqjUKr1xrU+djkwpOEzpA/bmfvNFvKLynszcuyNwfQ48+x0WlijQ== X-Received: by 2002:a1c:8dcd:: with SMTP id p196-v6mr999060wmd.49.1541577154427; Tue, 06 Nov 2018 23:52:34 -0800 (PST) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id p7-v6sm21276746wrs.23.2018.11.06.23.52.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 23:52:33 -0800 (PST) Date: Wed, 7 Nov 2018 07:52:32 +0000 From: Leif Lindholm To: Jian J Wang Cc: edk2-devel@lists.01.org, Star Zeng , Jiewen Yao , Ruiyu Ni Message-ID: <20181107075231.f5nv6dwsvfumys4r@bivouac.eciton.net> References: <20181107071248.6340-1-jian.j.wang@intel.com> <20181107071248.6340-2-jian.j.wang@intel.com> MIME-Version: 1.0 In-Reply-To: <20181107071248.6340-2-jian.j.wang@intel.com> User-Agent: NeoMutt/20170113 (1.7.2) 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 07:52:37 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 > 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 = 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 >