emacs-devel
[Top][All Lists]
Advanced

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

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


From: Jan Djärv
Subject: Re: [PATCH] lwlib: don't dereference NULL upon failed malloc
Date: Mon, 31 Jan 2011 07:45:45 +0100
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; sv-SE; rv:1.9.2.14) Gecko/20110123 Thunderbird/3.1.8

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<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]