all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] lwlib: don't dereference NULL upon failed malloc
@ 2011-01-30 15:04 Jim Meyering
  2011-01-31  6:45 ` Jan Djärv
  0 siblings, 1 reply; 2+ messages in thread
From: Jim Meyering @ 2011-01-30 15:04 UTC (permalink / raw)
  To: Emacs development discussions

A failed malloc here results in a NULL-dereference.
Obviously in "library-like" code (as this seems to be), it'd be better
to handle the NULL return, but since many callers already require
a non-NULL result, that would involve many more changes, for negligible
improvement, so using xmalloc looks best.

From c494bb91796af98db250bd26cb499f6a0bf61cba Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Sun, 30 Jan 2011 15:49:32 +0100
Subject: [PATCH] lwlib: don't dereference NULL upon failed malloc

* lwlib.c (malloc_widget_value): Use xmalloc, not malloc.
Numerous callers require a non-NULL return value.
---
 lwlib/ChangeLog |    6 ++++++
 lwlib/lwlib.c   |    2 +-
 2 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/lwlib/ChangeLog b/lwlib/ChangeLog
index 5015f2b..a5279ae 100644
--- a/lwlib/ChangeLog
+++ b/lwlib/ChangeLog
@@ -1,3 +1,9 @@
+2011-01-30  Jim Meyering  <meyering@redhat.com>
+
+	lwlib: don't dereference NULL upon failed malloc
+	* lwlib.c (malloc_widget_value): Use xmalloc, not malloc.
+	Numerous callers require a non-NULL return value.
+
 2011-01-25  Werner Meisner  <weme24@gmx.net>

 	* lwlib-Xm.c (xm_update_menu): Avoid a NULL pointer dereference
diff --git a/lwlib/lwlib.c b/lwlib/lwlib.c
index 677516a..9ca988b 100644
--- a/lwlib/lwlib.c
+++ b/lwlib/lwlib.c
@@ -157,7 +157,7 @@ malloc_widget_value (void)
     }
   else
     {
-      wv = (widget_value *) malloc (sizeof (widget_value));
+      wv = (widget_value *) xmalloc (sizeof (widget_value));
       malloc_cpt++;
     }
   memset ((void*) wv, 0, sizeof (widget_value));
--
1.7.3.5.44.g960a



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] lwlib: don't dereference NULL upon failed malloc
  2011-01-30 15:04 [PATCH] lwlib: don't dereference NULL upon failed malloc Jim Meyering
@ 2011-01-31  6:45 ` Jan Djärv
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Djärv @ 2011-01-31  6:45 UTC (permalink / raw)
  To: Jim Meyering; +Cc: Emacs development discussions

No use in changing just one place.  I changed all malloc in lwlib to xmalloc.

	Jan D.


Jim Meyering skrev 2011-01-30 16.04:
> A failed malloc here results in a NULL-dereference.
> Obviously in "library-like" code (as this seems to be), it'd be better
> to handle the NULL return, but since many callers already require
> a non-NULL result, that would involve many more changes, for negligible
> improvement, so using xmalloc looks best.
>
>> From c494bb91796af98db250bd26cb499f6a0bf61cba Mon Sep 17 00:00:00 2001
> From: Jim Meyering<meyering@redhat.com>
> Date: Sun, 30 Jan 2011 15:49:32 +0100
> Subject: [PATCH] lwlib: don't dereference NULL upon failed malloc
>
> * lwlib.c (malloc_widget_value): Use xmalloc, not malloc.
> Numerous callers require a non-NULL return value.
> ---
>   lwlib/ChangeLog |    6 ++++++
>   lwlib/lwlib.c   |    2 +-
>   2 files changed, 7 insertions(+), 1 deletions(-)
>
> diff --git a/lwlib/ChangeLog b/lwlib/ChangeLog
> index 5015f2b..a5279ae 100644
> --- a/lwlib/ChangeLog
> +++ b/lwlib/ChangeLog
> @@ -1,3 +1,9 @@
> +2011-01-30  Jim Meyering<meyering@redhat.com>
> +
> +	lwlib: don't dereference NULL upon failed malloc
> +	* lwlib.c (malloc_widget_value): Use xmalloc, not malloc.
> +	Numerous callers require a non-NULL return value.
> +
>   2011-01-25  Werner Meisner<weme24@gmx.net>
>
>   	* lwlib-Xm.c (xm_update_menu): Avoid a NULL pointer dereference
> diff --git a/lwlib/lwlib.c b/lwlib/lwlib.c
> index 677516a..9ca988b 100644
> --- a/lwlib/lwlib.c
> +++ b/lwlib/lwlib.c
> @@ -157,7 +157,7 @@ malloc_widget_value (void)
>       }
>     else
>       {
> -      wv = (widget_value *) malloc (sizeof (widget_value));
> +      wv = (widget_value *) xmalloc (sizeof (widget_value));
>         malloc_cpt++;
>       }
>     memset ((void*) wv, 0, sizeof (widget_value));
> --
> 1.7.3.5.44.g960a



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-01-31  6:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-30 15:04 [PATCH] lwlib: don't dereference NULL upon failed malloc Jim Meyering
2011-01-31  6:45 ` Jan Djärv

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.