From patchwork Wed Feb 24 21:13:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 62833 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp2643689lbl; Wed, 24 Feb 2016 13:14:06 -0800 (PST) X-Received: by 10.98.87.80 with SMTP id l77mr57844642pfb.101.1456348445010; Wed, 24 Feb 2016 13:14:05 -0800 (PST) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id mk9si7224725pab.101.2016.02.24.13.14.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Feb 2016 13:14:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 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 5AFD51A1F1C; Wed, 24 Feb 2016 13:14:08 -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 1EAC61A1EF4 for ; Wed, 24 Feb 2016 13:14:07 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id E4CCE85545; Wed, 24 Feb 2016 21:14:02 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-22.phx2.redhat.com [10.3.113.22]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1OLDt1a026826; Wed, 24 Feb 2016 16:14:01 -0500 From: Laszlo Ersek To: edk2-devel-01 Date: Wed, 24 Feb 2016 22:13:50 +0100 Message-Id: <1456348432-18818-3-git-send-email-lersek@redhat.com> In-Reply-To: <1456348432-18818-1-git-send-email-lersek@redhat.com> References: <1456348432-18818-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Cc: Ting Ye , David Woodhouse , Qin Long Subject: [edk2] [PATCH 2/4] CryptoPkg: RuntimeCryptLib: 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 RuntimeFreeMem() internal function. Therefore we must not forward the argument of free() to RuntimeFreeMem() without checking. Cc: David Woodhouse Cc: Qin Long Cc: Ting Ye Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c | 8 +++++++- 1 file changed, 7 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/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c index 616ee7717e72..45ef9ff5f252 100644 --- a/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c +++ b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c @@ -434,5 +434,11 @@ void *realloc (void *ptr, size_t size) /* Deallocates or frees a memory block */ void free (void *ptr) { - RuntimeFreeMem (ptr); + // + // In Standard C, free() handles a null pointer argument transparently. This + // is not true of RuntimeFreeMem() below, so protect it. + // + if (ptr != NULL) { + RuntimeFreeMem (ptr); + } }