]> granicus.if.org Git - libevent/commitdiff
we cannot realloc memory used by TAILQ; instead malloc each slot individually
authorNiels Provos <provos@gmail.com>
Thu, 25 Dec 2008 09:22:13 +0000 (09:22 +0000)
committerNiels Provos <provos@gmail.com>
Thu, 25 Dec 2008 09:22:13 +0000 (09:22 +0000)
svn:r977

event-internal.h
evmap.c

index 7bf4ca5849e0330058048045b4a9eda3246993d8..1255d931f8af3bc65716248588c42f73e7957334 100644 (file)
@@ -60,7 +60,7 @@ struct eventop {
 
 /* used to map multiple events to the same underlying identifier */
 struct event_map {
-       void *entries;
+       void **entries;
        int nentries;
 };
 
diff --git a/evmap.c b/evmap.c
index 288326717ca433080be457ff6fc0406be883aef3..1a753bc32bff6e8ade8304db25a3d845b7a6518c 100644 (file)
--- a/evmap.c
+++ b/evmap.c
@@ -56,8 +56,7 @@
 #include "evmap.h"
 #include "mm-internal.h"
 
-#define GET_SLOT(map, slot, type) \
-       (struct type *)((char *)(map)->entries + (slot)*(sizeof(struct type)))
+#define GET_SLOT(map, slot, type) (struct type *)((map)->entries[slot])
 
 static int
 evmap_make_space(
@@ -66,17 +65,20 @@ evmap_make_space(
        if (map->nentries <= slot) {
                int i;
                int nentries = map->nentries ? map->nentries : 32;
-               void *tmp;
+               void **tmp;
 
                while (nentries <= slot)
                        nentries <<= 1;
 
-               tmp = mm_realloc(map->entries, nentries * msize);
+               tmp = (void **)mm_realloc(map->entries, nentries * msize);
                if (tmp == NULL)
                        return (-1);
                
-               for (i = map->nentries; i < nentries; ++i)
-                       (*ctor)((char *)tmp + i * msize);
+               for (i = map->nentries; i < nentries; ++i) {
+                       tmp[i] = mm_malloc(msize);
+                       assert(tmp[i] != NULL);
+                       (*ctor)(tmp[i]);
+               }
 
                map->nentries = nentries;
                map->entries = tmp;
@@ -91,6 +93,9 @@ evmap_clear(struct event_map *ctx)
 {
        ctx->nentries = 0;
        if (ctx->entries != NULL) {
+               int i;
+               for (i = 0; i < ctx->nentries; ++i)
+                       mm_free(ctx->entries[i]);
                mm_free(ctx->entries);
                ctx->entries = NULL;
        }