diff mbox series

[8/9] libc: Check for NULL pointers in free()

Message ID 1526578856-30967-9-git-send-email-thuth@redhat.com
State Superseded
Headers show
Series Support network booting with pxelinux.cfg files | expand

Commit Message

Thomas Huth May 17, 2018, 5:40 p.m. UTC
POSIX says that the free() function should simply do nothing if a NULL
pointer argument has been specified. So let's be a little bit more
compliant in our libc and add a NULL pointer check here, too.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 lib/libc/stdlib/free.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Greg Kurz May 18, 2018, 10:10 a.m. UTC | #1
On Thu, 17 May 2018 19:40:55 +0200
Thomas Huth <thuth@redhat.com> wrote:

> POSIX says that the free() function should simply do nothing if a NULL
> pointer argument has been specified. So let's be a little bit more
> compliant in our libc and add a NULL pointer check here, too.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---

Reviewed-by: Greg Kurz <groug@kaod.org>

>  lib/libc/stdlib/free.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/libc/stdlib/free.c b/lib/libc/stdlib/free.c
> index 9005450..d276585 100644
> --- a/lib/libc/stdlib/free.c
> +++ b/lib/libc/stdlib/free.c
> @@ -19,8 +19,10 @@ free(void *ptr)
>  {
>  	struct chunk *header;
>  
> +	if (!ptr)
> +		return;
> +
>  	header = (struct chunk *) ptr;
>  	header--;
>  	header->inuse = 0;
> -
>  }
diff mbox series

Patch

diff --git a/lib/libc/stdlib/free.c b/lib/libc/stdlib/free.c
index 9005450..d276585 100644
--- a/lib/libc/stdlib/free.c
+++ b/lib/libc/stdlib/free.c
@@ -19,8 +19,10 @@  free(void *ptr)
 {
 	struct chunk *header;
 
+	if (!ptr)
+		return;
+
 	header = (struct chunk *) ptr;
 	header--;
 	header->inuse = 0;
-
 }