emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] lwlib: don't dereference NULL upon failed malloc


From: Jim Meyering
Subject: [PATCH] lwlib: don't dereference NULL upon failed malloc
Date: Sun, 30 Jan 2011 16:04:10 +0100

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 <address@hidden>
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  <address@hidden>
+
+       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  <address@hidden>

        * 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]