From patchwork Thu Feb 25 10:22:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 62870 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp80603lbc; Thu, 25 Feb 2016 02:22:23 -0800 (PST) X-Received: by 10.98.14.79 with SMTP id w76mr61526742pfi.1.1456395743806; Thu, 25 Feb 2016 02:22:23 -0800 (PST) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id u27si11639431pfi.159.2016.02.25.02.22.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Feb 2016 02:22:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 645D11A1DEF; Thu, 25 Feb 2016 02:22:27 -0800 (PST) X-Original-To: edk2-devel@ml01.01.org Delivered-To: edk2-devel@ml01.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 2248C1A1DED for ; Thu, 25 Feb 2016 02:22:27 -0800 (PST) Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 2881B7EBAE; Thu, 25 Feb 2016 10:22:22 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-26.phx2.redhat.com [10.3.113.26]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1PAMJS5013376; Thu, 25 Feb 2016 05:22:20 -0500 From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 25 Feb 2016 11:22:16 +0100 Message-Id: <1456395736-11784-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 Cc: Eric Dong , Cecil Sheng , Qiu Shumin , Yao Jiewen , Samer El-Haj-Mahmoud Subject: [edk2] [PATCH v2] MdeModulePkg: RegularExpressionDxe: support free(NULL) X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The ISO C standard says about free(), If ptr is a null pointer, no action occurs. This is not true of the FreePool() interface of the MemoryAllocationLib class: Buffer must have been allocated on a previous call to the pool allocation services of the Memory Allocation Library. [...] If Buffer was not allocated with a pool allocation function in the Memory Allocation Library, then ASSERT(). Therefore we must not forward the argument of free() to FreePool() without checking. Cc: Cecil Sheng Cc: Cinnamon Shia Cc: Eric Dong Cc: Qiu Shumin Cc: Samer El-Haj-Mahmoud Cc: Yao Jiewen Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- Notes: v2: - Drop incorrect explicit (VOID *) cast in assignment to EvalOnce. - Build-tested only. v1: - Build-tested only. MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/OnigurumaUefiPort.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) -- 1.8.3.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/OnigurumaUefiPort.h b/MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/OnigurumaUefiPort.h index cb791f8c84c6..ca478de68e77 100644 --- a/MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/OnigurumaUefiPort.h +++ b/MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/OnigurumaUefiPort.h @@ -30,7 +30,17 @@ typedef UINTN size_t; #define malloc(n) AllocatePool(n) #define calloc(n,s) AllocateZeroPool((n)*(s)) -#define free(p) FreePool(p) + +#define free(p) \ + do { \ + VOID *EvalOnce; \ + \ + EvalOnce = (p); \ + if (EvalOnce != NULL) { \ + FreePool (EvalOnce); \ + } \ + } while (FALSE) + #define realloc(OldPtr,NewSize,OldSize) ReallocatePool(OldSize,NewSize,OldPtr) #define xmemmove(Dest,Src,Length) CopyMem(Dest,Src,Length) #define xmemcpy(Dest,Src,Length) CopyMem(Dest,Src,Length)