mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-10 13:04:23 -04:00
we cannot realloc memory used by TAILQ; instead malloc each slot individually
svn:r977
This commit is contained in:
parent
17bfc07e94
commit
30cba6d0b3
@ -60,7 +60,7 @@ struct eventop {
|
|||||||
|
|
||||||
/* used to map multiple events to the same underlying identifier */
|
/* used to map multiple events to the same underlying identifier */
|
||||||
struct event_map {
|
struct event_map {
|
||||||
void *entries;
|
void **entries;
|
||||||
int nentries;
|
int nentries;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
17
evmap.c
17
evmap.c
@ -56,8 +56,7 @@
|
|||||||
#include "evmap.h"
|
#include "evmap.h"
|
||||||
#include "mm-internal.h"
|
#include "mm-internal.h"
|
||||||
|
|
||||||
#define GET_SLOT(map, slot, type) \
|
#define GET_SLOT(map, slot, type) (struct type *)((map)->entries[slot])
|
||||||
(struct type *)((char *)(map)->entries + (slot)*(sizeof(struct type)))
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
evmap_make_space(
|
evmap_make_space(
|
||||||
@ -66,17 +65,20 @@ evmap_make_space(
|
|||||||
if (map->nentries <= slot) {
|
if (map->nentries <= slot) {
|
||||||
int i;
|
int i;
|
||||||
int nentries = map->nentries ? map->nentries : 32;
|
int nentries = map->nentries ? map->nentries : 32;
|
||||||
void *tmp;
|
void **tmp;
|
||||||
|
|
||||||
while (nentries <= slot)
|
while (nentries <= slot)
|
||||||
nentries <<= 1;
|
nentries <<= 1;
|
||||||
|
|
||||||
tmp = mm_realloc(map->entries, nentries * msize);
|
tmp = (void **)mm_realloc(map->entries, nentries * msize);
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
for (i = map->nentries; i < nentries; ++i)
|
for (i = map->nentries; i < nentries; ++i) {
|
||||||
(*ctor)((char *)tmp + i * msize);
|
tmp[i] = mm_malloc(msize);
|
||||||
|
assert(tmp[i] != NULL);
|
||||||
|
(*ctor)(tmp[i]);
|
||||||
|
}
|
||||||
|
|
||||||
map->nentries = nentries;
|
map->nentries = nentries;
|
||||||
map->entries = tmp;
|
map->entries = tmp;
|
||||||
@ -91,6 +93,9 @@ evmap_clear(struct event_map *ctx)
|
|||||||
{
|
{
|
||||||
ctx->nentries = 0;
|
ctx->nentries = 0;
|
||||||
if (ctx->entries != NULL) {
|
if (ctx->entries != NULL) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < ctx->nentries; ++i)
|
||||||
|
mm_free(ctx->entries[i]);
|
||||||
mm_free(ctx->entries);
|
mm_free(ctx->entries);
|
||||||
ctx->entries = NULL;
|
ctx->entries = NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user