]> granicus.if.org Git - libevent/commitdiff
Add some missing checks for mm_calloc failures
authorNick Mathewson <nickm@torproject.org>
Wed, 8 Jun 2011 18:18:41 +0000 (14:18 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 8 Jun 2011 18:23:37 +0000 (14:23 -0400)
Found by Gilad Benjamini

buffer_iocp.c
evmap.c

index 67c89c2a27913734aa863290484288efc7d4a263..f3f96f4408dd1327de1e38b79af9e083451f81fe 100644 (file)
@@ -150,6 +150,8 @@ evbuffer_overlapped_new(evutil_socket_t fd)
        struct evbuffer_overlapped *evo;
 
        evo = mm_calloc(1, sizeof(struct evbuffer_overlapped));
+       if (!evo)
+               return NULL;
 
        TAILQ_INIT(&evo->buffer.callbacks);
        evo->buffer.refcnt = 1;
diff --git a/evmap.c b/evmap.c
index ebedb7881437e9c4e04d198cfb155da5eea6bd62..f33799882fcc936699157cf74849ac6c93c401d8 100644 (file)
--- a/evmap.c
+++ b/evmap.c
@@ -127,7 +127,8 @@ HT_GENERATE(event_io_map, event_map_entry, map_node, hashsocket, eqsocket,
                    },                                                  \
                    {                                                   \
                            _ent = mm_calloc(1,sizeof(struct event_map_entry)+fdinfo_len); \
-                           EVUTIL_ASSERT(_ent);                                \
+                           if (EVUTIL_UNLIKELY(_ent == NULL))          \
+                                   return (-1);                        \
                            _ent->fd = slot;                            \
                            (ctor)(&_ent->ent.type);                    \
                            _HT_FOI_INSERT(map_node, map, &_key, _ent, ptr) \
@@ -159,14 +160,16 @@ void evmap_io_clear(struct event_io_map *ctx)
        (x) = (struct type *)((map)->entries[slot])
 /* As GET_SLOT, but construct the entry for 'slot' if it is not present,
    by allocating enough memory for a 'struct type', and initializing the new
-   value by calling the function 'ctor' on it.
+   value by calling the function 'ctor' on it.  Makes the function
+   return -1 on allocation failure.
  */
 #define GET_SIGNAL_SLOT_AND_CTOR(x, map, slot, type, ctor, fdinfo_len) \
        do {                                                            \
                if ((map)->entries[slot] == NULL) {                     \
                        (map)->entries[slot] =                          \
                            mm_calloc(1,sizeof(struct type)+fdinfo_len); \
-                       EVUTIL_ASSERT((map)->entries[slot] != NULL);            \
+                       if (EVUTIL_UNLIKELY((map)->entries[slot] == NULL)) \
+                               return (-1);                            \
                        (ctor)((struct type *)(map)->entries[slot]);    \
                }                                                       \
                (x) = (struct type *)((map)->entries[slot]);            \