mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
r14939@tombo: nickm | 2007-11-25 11:59:26 -0500
New function event_set_mem_functions to replace internal calls to malloc, free, etc with a user-supplied functions. svn:r541
This commit is contained in:
parent
98b5453ecd
commit
7eb250e9c5
@ -6,6 +6,8 @@ Changes in current version:
|
||||
o improve documentation on event_base_loopexit; patch from Scott Lamb
|
||||
o New function, event_{base_}loopbreak. Like event_loopexit, it makes an event loop stop executing and return. Unlike event_loopexit, it keeps subsequent pending events from getting executed. Patch from Scott Lamb
|
||||
o provide event_reinit() to reintialize an event_base after fork
|
||||
o New function event_set_mem_functinons. It allows the user to give libevent replacement functions to use for memory management in place of malloc(), free(), etc. This should be generally useful for memory instrumentation, specialized allocators, and so on.
|
||||
|
||||
|
||||
Changes in 1.4.0:
|
||||
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
|
||||
|
@ -82,7 +82,7 @@ event-config.h: config.h
|
||||
|
||||
CORE_SRC = event.c buffer.c evbuffer.c log.c evutil.c $(SYS_SRC)
|
||||
EXTRA_SRC = event_tagging.c http.c evhttp.h http-internal.h evdns.c \
|
||||
evdns.h evrpc.c evrpc.h evrpc-internal.h \
|
||||
evdns.h evrpc.c evrpc.h evrpc-internal.h mm-internal.h \
|
||||
strlcpy.c strlcpy-internal.h strlcpy-internal.h
|
||||
|
||||
libevent_la_SOURCES = $(CORE_SRC) $(EXTRA_SRC)
|
||||
|
@ -47,7 +47,7 @@
|
||||
#include "event.h"
|
||||
#include "event-internal.h"
|
||||
|
||||
#define XFREE(ptr) do { if (ptr) free(ptr); } while(0)
|
||||
#define XFREE(ptr) do { if (ptr) event_free(ptr); } while(0)
|
||||
|
||||
extern struct event_list timequeue;
|
||||
extern struct event_list addqueue;
|
||||
@ -174,23 +174,23 @@ win32_init(struct event_base *_base)
|
||||
{
|
||||
struct win32op *winop;
|
||||
size_t size;
|
||||
if (!(winop = calloc(1, sizeof(struct win32op))))
|
||||
if (!(winop = event_calloc(1, sizeof(struct win32op))))
|
||||
return NULL;
|
||||
winop->fd_setsz = NEVENT;
|
||||
size = FD_SET_ALLOC_SIZE(NEVENT);
|
||||
if (!(winop->readset_in = malloc(size)))
|
||||
if (!(winop->readset_in = event_malloc(size)))
|
||||
goto err;
|
||||
if (!(winop->writeset_in = malloc(size)))
|
||||
if (!(winop->writeset_in = event_malloc(size)))
|
||||
goto err;
|
||||
if (!(winop->readset_out = malloc(size)))
|
||||
if (!(winop->readset_out = event_malloc(size)))
|
||||
goto err;
|
||||
if (!(winop->writeset_out = malloc(size)))
|
||||
if (!(winop->writeset_out = event_malloc(size)))
|
||||
goto err;
|
||||
if (!(winop->exset_out = malloc(size)))
|
||||
if (!(winop->exset_out = event_malloc(size)))
|
||||
goto err;
|
||||
winop->n_events = 0;
|
||||
winop->n_events_alloc = NEVENT;
|
||||
if (!(winop->events = malloc(NEVENT*sizeof(struct event*))))
|
||||
if (!(winop->events = event_malloc(NEVENT*sizeof(struct event*))))
|
||||
goto err;
|
||||
winop->readset_in->fd_count = winop->writeset_in->fd_count = 0;
|
||||
winop->readset_out->fd_count = winop->writeset_out->fd_count
|
||||
@ -252,7 +252,7 @@ win32_insert(void *op, struct event *ev)
|
||||
size_t sz;
|
||||
win32op->n_events_alloc *= 2;
|
||||
sz = sizeof(struct event*)*win32op->n_events_alloc;
|
||||
if (!(win32op->events = realloc(win32op->events, sz)))
|
||||
if (!(win32op->events = event_realloc(win32op->events, sz)))
|
||||
return (-1);
|
||||
}
|
||||
win32op->events[win32op->n_events++] = ev;
|
||||
@ -388,20 +388,20 @@ win32_dealloc(struct event_base *_base, void *arg)
|
||||
|
||||
evsignal_dealloc(_base);
|
||||
if (win32op->readset_in)
|
||||
free(win32op->readset_in);
|
||||
event_free(win32op->readset_in);
|
||||
if (win32op->writeset_in)
|
||||
free(win32op->writeset_in);
|
||||
event_free(win32op->writeset_in);
|
||||
if (win32op->readset_out)
|
||||
free(win32op->readset_out);
|
||||
event_free(win32op->readset_out);
|
||||
if (win32op->writeset_out)
|
||||
free(win32op->writeset_out);
|
||||
event_free(win32op->writeset_out);
|
||||
if (win32op->exset_out)
|
||||
free(win32op->exset_out);
|
||||
event_free(win32op->exset_out);
|
||||
if (win32op->events)
|
||||
free(win32op->events);
|
||||
event_free(win32op->events);
|
||||
|
||||
memset(win32op, 0, sizeof(win32op));
|
||||
free(win32op);
|
||||
event_free(win32op);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
11
buffer.c
11
buffer.c
@ -63,13 +63,14 @@
|
||||
|
||||
#include "event.h"
|
||||
#include "config.h"
|
||||
#include "mm-internal.h"
|
||||
|
||||
struct evbuffer *
|
||||
evbuffer_new(void)
|
||||
{
|
||||
struct evbuffer *buffer;
|
||||
|
||||
buffer = calloc(1, sizeof(struct evbuffer));
|
||||
buffer = event_calloc(1, sizeof(struct evbuffer));
|
||||
|
||||
return (buffer);
|
||||
}
|
||||
@ -78,8 +79,8 @@ void
|
||||
evbuffer_free(struct evbuffer *buffer)
|
||||
{
|
||||
if (buffer->orig_buffer != NULL)
|
||||
free(buffer->orig_buffer);
|
||||
free(buffer);
|
||||
event_free(buffer->orig_buffer);
|
||||
event_free(buffer);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -227,7 +228,7 @@ evbuffer_readline(struct evbuffer *buffer)
|
||||
if (i == len)
|
||||
return (NULL);
|
||||
|
||||
if ((line = malloc(i + 1)) == NULL) {
|
||||
if ((line = event_malloc(i + 1)) == NULL) {
|
||||
fprintf(stderr, "%s: out of memory\n", __func__);
|
||||
evbuffer_drain(buffer, i);
|
||||
return (NULL);
|
||||
@ -291,7 +292,7 @@ evbuffer_expand(struct evbuffer *buf, size_t datlen)
|
||||
|
||||
if (buf->orig_buffer != buf->buffer)
|
||||
evbuffer_align(buf);
|
||||
if ((newbuf = realloc(buf->buffer, length)) == NULL)
|
||||
if ((newbuf = event_realloc(buf->buffer, length)) == NULL)
|
||||
return (-1);
|
||||
|
||||
buf->orig_buffer = buf->buffer = newbuf;
|
||||
|
32
devpoll.c
32
devpoll.c
@ -135,7 +135,7 @@ devpoll_init(struct event_base *base)
|
||||
if (getenv("EVENT_NODEVPOLL"))
|
||||
return (NULL);
|
||||
|
||||
if (!(devpollop = calloc(1, sizeof(struct devpollop))))
|
||||
if (!(devpollop = event_calloc(1, sizeof(struct devpollop))))
|
||||
return (NULL);
|
||||
|
||||
if (getrlimit(RLIMIT_NOFILE, &rl) == 0 &&
|
||||
@ -145,35 +145,35 @@ devpoll_init(struct event_base *base)
|
||||
/* Initialize the kernel queue */
|
||||
if ((dpfd = open("/dev/poll", O_RDWR)) == -1) {
|
||||
event_warn("open: /dev/poll");
|
||||
free(devpollop);
|
||||
event_free(devpollop);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
devpollop->dpfd = dpfd;
|
||||
|
||||
/* Initialize fields */
|
||||
devpollop->events = calloc(nfiles, sizeof(struct pollfd));
|
||||
devpollop->events = event_calloc(nfiles, sizeof(struct pollfd));
|
||||
if (devpollop->events == NULL) {
|
||||
free(devpollop);
|
||||
event_free(devpollop);
|
||||
close(dpfd);
|
||||
return (NULL);
|
||||
}
|
||||
devpollop->nevents = nfiles;
|
||||
|
||||
devpollop->fds = calloc(nfiles, sizeof(struct evdevpoll));
|
||||
devpollop->fds = event_calloc(nfiles, sizeof(struct evdevpoll));
|
||||
if (devpollop->fds == NULL) {
|
||||
free(devpollop->events);
|
||||
free(devpollop);
|
||||
event_free(devpollop->events);
|
||||
event_free(devpollop);
|
||||
close(dpfd);
|
||||
return (NULL);
|
||||
}
|
||||
devpollop->nfds = nfiles;
|
||||
|
||||
devpollop->changes = calloc(nfiles, sizeof(struct pollfd));
|
||||
devpollop->changes = event_calloc(nfiles, sizeof(struct pollfd));
|
||||
if (devpollop->changes == NULL) {
|
||||
free(devpollop->fds);
|
||||
free(devpollop->events);
|
||||
free(devpollop);
|
||||
event_free(devpollop->fds);
|
||||
event_free(devpollop->events);
|
||||
event_free(devpollop);
|
||||
close(dpfd);
|
||||
return (NULL);
|
||||
}
|
||||
@ -196,7 +196,7 @@ devpoll_recalc(struct event_base *base, void *arg, int max)
|
||||
while (nfds < max)
|
||||
nfds <<= 1;
|
||||
|
||||
fds = realloc(devpollop->fds, nfds * sizeof(struct evdevpoll));
|
||||
fds = event_realloc(devpollop->fds, nfds * sizeof(struct evdevpoll));
|
||||
if (fds == NULL) {
|
||||
event_warn("realloc");
|
||||
return (-1);
|
||||
@ -405,14 +405,14 @@ devpoll_dealloc(struct event_base *base, void *arg)
|
||||
|
||||
evsignal_dealloc(base);
|
||||
if (devpollop->fds)
|
||||
free(devpollop->fds);
|
||||
event_free(devpollop->fds);
|
||||
if (devpollop->events)
|
||||
free(devpollop->events);
|
||||
event_free(devpollop->events);
|
||||
if (devpollop->changes)
|
||||
free(devpollop->changes);
|
||||
event_free(devpollop->changes);
|
||||
if (devpollop->dpfd >= 0)
|
||||
close(devpollop->dpfd);
|
||||
|
||||
memset(devpollop, 0, sizeof(struct devpollop));
|
||||
free(devpollop);
|
||||
event_free(devpollop);
|
||||
}
|
||||
|
20
epoll.c
20
epoll.c
@ -128,23 +128,23 @@ epoll_init(struct event_base *base)
|
||||
|
||||
FD_CLOSEONEXEC(epfd);
|
||||
|
||||
if (!(epollop = calloc(1, sizeof(struct epollop))))
|
||||
if (!(epollop = event_calloc(1, sizeof(struct epollop))))
|
||||
return (NULL);
|
||||
|
||||
epollop->epfd = epfd;
|
||||
|
||||
/* Initalize fields */
|
||||
epollop->events = malloc(nfiles * sizeof(struct epoll_event));
|
||||
epollop->events = event_malloc(nfiles * sizeof(struct epoll_event));
|
||||
if (epollop->events == NULL) {
|
||||
free(epollop);
|
||||
event_free(epollop);
|
||||
return (NULL);
|
||||
}
|
||||
epollop->nevents = nfiles;
|
||||
|
||||
epollop->fds = calloc(nfiles, sizeof(struct evepoll));
|
||||
epollop->fds = event_calloc(nfiles, sizeof(struct evepoll));
|
||||
if (epollop->fds == NULL) {
|
||||
free(epollop->events);
|
||||
free(epollop);
|
||||
event_free(epollop->events);
|
||||
event_free(epollop);
|
||||
return (NULL);
|
||||
}
|
||||
epollop->nfds = nfiles;
|
||||
@ -167,7 +167,7 @@ epoll_recalc(struct event_base *base, void *arg, int max)
|
||||
while (nfds < max)
|
||||
nfds <<= 1;
|
||||
|
||||
fds = realloc(epollop->fds, nfds * sizeof(struct evepoll));
|
||||
fds = event_realloc(epollop->fds, nfds * sizeof(struct evepoll));
|
||||
if (fds == NULL) {
|
||||
event_warn("realloc");
|
||||
return (-1);
|
||||
@ -352,12 +352,12 @@ epoll_dealloc(struct event_base *base, void *arg)
|
||||
|
||||
evsignal_dealloc(base);
|
||||
if (epollop->fds)
|
||||
free(epollop->fds);
|
||||
event_free(epollop->fds);
|
||||
if (epollop->events)
|
||||
free(epollop->events);
|
||||
event_free(epollop->events);
|
||||
if (epollop->epfd >= 0)
|
||||
close(epollop->epfd);
|
||||
|
||||
memset(epollop, 0, sizeof(struct epollop));
|
||||
free(epollop);
|
||||
event_free(epollop);
|
||||
}
|
||||
|
@ -49,6 +49,7 @@
|
||||
|
||||
#include "evutil.h"
|
||||
#include "event.h"
|
||||
#include "mm-internal.h"
|
||||
|
||||
/* prototypes */
|
||||
|
||||
@ -229,17 +230,17 @@ bufferevent_new(int fd, evbuffercb readcb, evbuffercb writecb,
|
||||
{
|
||||
struct bufferevent *bufev;
|
||||
|
||||
if ((bufev = calloc(1, sizeof(struct bufferevent))) == NULL)
|
||||
if ((bufev = event_calloc(1, sizeof(struct bufferevent))) == NULL)
|
||||
return (NULL);
|
||||
|
||||
if ((bufev->input = evbuffer_new()) == NULL) {
|
||||
free(bufev);
|
||||
event_free(bufev);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if ((bufev->output = evbuffer_new()) == NULL) {
|
||||
evbuffer_free(bufev->input);
|
||||
free(bufev);
|
||||
event_free(bufev);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@ -284,7 +285,7 @@ bufferevent_free(struct bufferevent *bufev)
|
||||
evbuffer_free(bufev->input);
|
||||
evbuffer_free(bufev->output);
|
||||
|
||||
free(bufev);
|
||||
event_free(bufev);
|
||||
}
|
||||
|
||||
/*
|
||||
|
114
evdns.c
114
evdns.c
@ -106,6 +106,7 @@
|
||||
#include "evdns.h"
|
||||
#include "evutil.h"
|
||||
#include "log.h"
|
||||
#include "mm-internal.h"
|
||||
#ifdef WIN32
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
@ -152,7 +153,6 @@ typedef unsigned int uint;
|
||||
#define open _open
|
||||
#define read _read
|
||||
#define close _close
|
||||
#define strdup _strdup
|
||||
#endif
|
||||
|
||||
#define MAX_ADDRS 32 /* maximum number of addresses from a single packet */
|
||||
@ -586,13 +586,13 @@ request_finished(struct request *const req, struct request **head) {
|
||||
|
||||
if (!req->request_appended) {
|
||||
/* need to free the request data on it's own */
|
||||
free(req->request);
|
||||
event_free(req->request);
|
||||
} else {
|
||||
/* the request data is appended onto the header */
|
||||
/* so everything gets free()ed when we: */
|
||||
}
|
||||
|
||||
free(req);
|
||||
event_free(req);
|
||||
|
||||
evdns_requests_pump_waiting_queue();
|
||||
}
|
||||
@ -970,7 +970,7 @@ request_parse(u8 *packet, int length, struct evdns_server_port *port, struct soc
|
||||
if (flags & 0x8000) return -1; /* Must not be an answer. */
|
||||
flags &= 0x0110; /* Only RD and CD get preserved. */
|
||||
|
||||
server_req = malloc(sizeof(struct server_request));
|
||||
server_req = event_malloc(sizeof(struct server_request));
|
||||
if (server_req == NULL) return -1;
|
||||
memset(server_req, 0, sizeof(struct server_request));
|
||||
|
||||
@ -980,7 +980,7 @@ request_parse(u8 *packet, int length, struct evdns_server_port *port, struct soc
|
||||
|
||||
server_req->base.flags = flags;
|
||||
server_req->base.nquestions = 0;
|
||||
server_req->base.questions = malloc(sizeof(struct evdns_server_question *) * questions);
|
||||
server_req->base.questions = event_malloc(sizeof(struct evdns_server_question *) * questions);
|
||||
if (server_req->base.questions == NULL)
|
||||
goto err;
|
||||
|
||||
@ -993,7 +993,7 @@ request_parse(u8 *packet, int length, struct evdns_server_port *port, struct soc
|
||||
GET16(type);
|
||||
GET16(class);
|
||||
namelen = strlen(tmp_name);
|
||||
q = malloc(sizeof(struct evdns_server_question) + namelen);
|
||||
q = event_malloc(sizeof(struct evdns_server_question) + namelen);
|
||||
if (!q)
|
||||
goto err;
|
||||
q->type = type;
|
||||
@ -1020,10 +1020,10 @@ err:
|
||||
if (server_req) {
|
||||
if (server_req->base.questions) {
|
||||
for (i = 0; i < server_req->base.nquestions; ++i)
|
||||
free(server_req->base.questions[i]);
|
||||
free(server_req->base.questions);
|
||||
event_free(server_req->base.questions[i]);
|
||||
event_free(server_req->base.questions);
|
||||
}
|
||||
free(server_req);
|
||||
event_free(server_req);
|
||||
}
|
||||
return -1;
|
||||
|
||||
@ -1292,7 +1292,7 @@ dnslabel_clear(struct dnslabel_table *table)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < table->n_labels; ++i)
|
||||
free(table->labels[i].v);
|
||||
event_free(table->labels[i].v);
|
||||
table->n_labels = 0;
|
||||
}
|
||||
|
||||
@ -1317,7 +1317,7 @@ dnslabel_table_add(struct dnslabel_table *table, const char *label, off_t pos)
|
||||
int p;
|
||||
if (table->n_labels == MAX_LABELS)
|
||||
return (-1);
|
||||
v = strdup(label);
|
||||
v = event_strdup(label);
|
||||
if (v == NULL)
|
||||
return (-1);
|
||||
p = table->n_labels++;
|
||||
@ -1450,7 +1450,7 @@ struct evdns_server_port *
|
||||
evdns_add_server_port(int socket, int is_tcp, evdns_request_callback_fn_type cb, void *user_data)
|
||||
{
|
||||
struct evdns_server_port *port;
|
||||
if (!(port = malloc(sizeof(struct evdns_server_port))))
|
||||
if (!(port = event_malloc(sizeof(struct evdns_server_port))))
|
||||
return NULL;
|
||||
memset(port, 0, sizeof(struct evdns_server_port));
|
||||
|
||||
@ -1508,12 +1508,12 @@ evdns_server_request_add_reply(struct evdns_server_request *_req, int section, c
|
||||
while (*itemp) {
|
||||
itemp = &((*itemp)->next);
|
||||
}
|
||||
item = malloc(sizeof(struct server_reply_item));
|
||||
item = event_malloc(sizeof(struct server_reply_item));
|
||||
if (!item)
|
||||
return -1;
|
||||
item->next = NULL;
|
||||
if (!(item->name = strdup(name))) {
|
||||
free(item);
|
||||
if (!(item->name = event_strdup(name))) {
|
||||
event_free(item);
|
||||
return -1;
|
||||
}
|
||||
item->type = type;
|
||||
@ -1524,16 +1524,16 @@ evdns_server_request_add_reply(struct evdns_server_request *_req, int section, c
|
||||
item->data = NULL;
|
||||
if (data) {
|
||||
if (item->is_name) {
|
||||
if (!(item->data = strdup(data))) {
|
||||
free(item->name);
|
||||
free(item);
|
||||
if (!(item->data = event_strdup(data))) {
|
||||
event_free(item->name);
|
||||
event_free(item);
|
||||
return -1;
|
||||
}
|
||||
item->datalen = (u16)-1;
|
||||
} else {
|
||||
if (!(item->data = malloc(datalen))) {
|
||||
free(item->name);
|
||||
free(item);
|
||||
if (!(item->data = event_malloc(datalen))) {
|
||||
event_free(item->name);
|
||||
event_free(item);
|
||||
return -1;
|
||||
}
|
||||
item->datalen = datalen;
|
||||
@ -1682,7 +1682,7 @@ overflow:
|
||||
|
||||
req->response_len = j;
|
||||
|
||||
if (!(req->response = malloc(req->response_len))) {
|
||||
if (!(req->response = event_malloc(req->response_len))) {
|
||||
server_request_free_answers(req);
|
||||
dnslabel_clear(&table);
|
||||
return (-1);
|
||||
@ -1759,10 +1759,10 @@ server_request_free_answers(struct server_request *req)
|
||||
victim = *list;
|
||||
while (victim) {
|
||||
next = victim->next;
|
||||
free(victim->name);
|
||||
event_free(victim->name);
|
||||
if (victim->data)
|
||||
free(victim->data);
|
||||
free(victim);
|
||||
event_free(victim->data);
|
||||
event_free(victim);
|
||||
victim = next;
|
||||
}
|
||||
*list = NULL;
|
||||
@ -1777,8 +1777,8 @@ server_request_free(struct server_request *req)
|
||||
int i, rc=1;
|
||||
if (req->base.questions) {
|
||||
for (i = 0; i < req->base.nquestions; ++i)
|
||||
free(req->base.questions[i]);
|
||||
free(req->base.questions);
|
||||
event_free(req->base.questions[i]);
|
||||
event_free(req->base.questions);
|
||||
}
|
||||
|
||||
if (req->port) {
|
||||
@ -1792,7 +1792,7 @@ server_request_free(struct server_request *req)
|
||||
}
|
||||
|
||||
if (req->response) {
|
||||
free(req->response);
|
||||
event_free(req->response);
|
||||
}
|
||||
|
||||
server_request_free_answers(req);
|
||||
@ -1804,10 +1804,10 @@ server_request_free(struct server_request *req)
|
||||
|
||||
if (rc == 0) {
|
||||
server_port_free(req->port);
|
||||
free(req);
|
||||
event_free(req);
|
||||
return (1);
|
||||
}
|
||||
free(req);
|
||||
event_free(req);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -2029,7 +2029,7 @@ evdns_clear_nameservers_and_suspend(void)
|
||||
(void) evtimer_del(&server->timeout_event);
|
||||
if (server->socket >= 0)
|
||||
CLOSE_SOCKET(server->socket);
|
||||
free(server);
|
||||
event_free(server);
|
||||
if (next == started_at)
|
||||
break;
|
||||
server = next;
|
||||
@ -2088,7 +2088,7 @@ _evdns_nameserver_add_impl(unsigned long int address, int port) {
|
||||
} while (server != started_at);
|
||||
}
|
||||
|
||||
ns = (struct nameserver *) malloc(sizeof(struct nameserver));
|
||||
ns = (struct nameserver *) event_malloc(sizeof(struct nameserver));
|
||||
if (!ns) return -1;
|
||||
|
||||
memset(ns, 0, sizeof(struct nameserver));
|
||||
@ -2134,7 +2134,7 @@ _evdns_nameserver_add_impl(unsigned long int address, int port) {
|
||||
out2:
|
||||
CLOSE_SOCKET(ns->socket);
|
||||
out1:
|
||||
free(ns);
|
||||
event_free(ns);
|
||||
log(EVDNS_LOG_WARN, "Unable to add nameserver %s: error %d", debug_ntoa(address), err);
|
||||
return err;
|
||||
}
|
||||
@ -2210,7 +2210,7 @@ request_new(int type, const char *name, int flags,
|
||||
const u16 trans_id = issuing_now ? transaction_id_pick() : 0xffff;
|
||||
/* the request data is alloced in a single block with the header */
|
||||
struct request *const req =
|
||||
(struct request *) malloc(sizeof(struct request) + request_max_len);
|
||||
(struct request *) event_malloc(sizeof(struct request) + request_max_len);
|
||||
int rlen;
|
||||
(void) flags;
|
||||
|
||||
@ -2236,7 +2236,7 @@ request_new(int type, const char *name, int flags,
|
||||
|
||||
return req;
|
||||
err1:
|
||||
free(req);
|
||||
event_free(req);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -2364,15 +2364,15 @@ search_state_decref(struct search_state *const state) {
|
||||
struct search_domain *next, *dom;
|
||||
for (dom = state->head; dom; dom = next) {
|
||||
next = dom->next;
|
||||
free(dom);
|
||||
event_free(dom);
|
||||
}
|
||||
free(state);
|
||||
event_free(state);
|
||||
}
|
||||
}
|
||||
|
||||
static struct search_state *
|
||||
search_state_new(void) {
|
||||
struct search_state *state = (struct search_state *) malloc(sizeof(struct search_state));
|
||||
struct search_state *state = (struct search_state *) event_malloc(sizeof(struct search_state));
|
||||
if (!state) return NULL;
|
||||
memset(state, 0, sizeof(struct search_state));
|
||||
state->refcount = 1;
|
||||
@ -2405,7 +2405,7 @@ search_postfix_add(const char *domain) {
|
||||
if (!global_search_state) return;
|
||||
global_search_state->num_domains++;
|
||||
|
||||
sdomain = (struct search_domain *) malloc(sizeof(struct search_domain) + domain_len);
|
||||
sdomain = (struct search_domain *) event_malloc(sizeof(struct search_domain) + domain_len);
|
||||
if (!sdomain) return;
|
||||
memcpy( ((u8 *) sdomain) + sizeof(struct search_domain), domain, domain_len);
|
||||
sdomain->next = global_search_state->head;
|
||||
@ -2468,7 +2468,7 @@ search_make_new(const struct search_state *const state, int n, const char *const
|
||||
/* the actual postfix string is kept at the end of the structure */
|
||||
const u8 *const postfix = ((u8 *) dom) + sizeof(struct search_domain);
|
||||
const int postfix_len = dom->len;
|
||||
char *const newname = (char *) malloc(base_len + need_to_append_dot + postfix_len + 1);
|
||||
char *const newname = (char *) event_malloc(base_len + need_to_append_dot + postfix_len + 1);
|
||||
if (!newname) return NULL;
|
||||
memcpy(newname, base_name, base_len);
|
||||
if (need_to_append_dot) newname[base_len] = '.';
|
||||
@ -2499,11 +2499,11 @@ search_request_new(int type, const char *const name, int flags, evdns_callback_t
|
||||
char *const new_name = search_make_new(global_search_state, 0, name);
|
||||
if (!new_name) return 1;
|
||||
req = request_new(type, new_name, flags, user_callback, user_arg);
|
||||
free(new_name);
|
||||
event_free(new_name);
|
||||
if (!req) return 1;
|
||||
req->search_index = 0;
|
||||
}
|
||||
req->search_origname = strdup(name);
|
||||
req->search_origname = event_strdup(name);
|
||||
req->search_state = global_search_state;
|
||||
req->search_flags = flags;
|
||||
global_search_state->refcount++;
|
||||
@ -2548,7 +2548,7 @@ search_try_next(struct request *const req) {
|
||||
if (!new_name) return 1;
|
||||
log(EVDNS_LOG_DEBUG, "Search: now trying %s (%d)", new_name, req->search_index);
|
||||
newreq = request_new(req->request_type, new_name, req->search_flags, req->user_callback, req->user_pointer);
|
||||
free(new_name);
|
||||
event_free(new_name);
|
||||
if (!newreq) return 1;
|
||||
newreq->search_origname = req->search_origname;
|
||||
req->search_origname = NULL;
|
||||
@ -2569,7 +2569,7 @@ search_request_finished(struct request *const req) {
|
||||
req->search_state = NULL;
|
||||
}
|
||||
if (req->search_origname) {
|
||||
free(req->search_origname);
|
||||
event_free(req->search_origname);
|
||||
req->search_origname = NULL;
|
||||
}
|
||||
}
|
||||
@ -2731,7 +2731,7 @@ evdns_resolv_conf_parse(int flags, const char *const filename) {
|
||||
}
|
||||
if (st.st_size > 65535) { err = 3; goto out1; } /* no resolv.conf should be any bigger */
|
||||
|
||||
resolv = (u8 *) malloc((size_t)st.st_size + 1);
|
||||
resolv = (u8 *) event_malloc((size_t)st.st_size + 1);
|
||||
if (!resolv) { err = 4; goto out1; }
|
||||
|
||||
n = 0;
|
||||
@ -2767,7 +2767,7 @@ evdns_resolv_conf_parse(int flags, const char *const filename) {
|
||||
}
|
||||
|
||||
out2:
|
||||
free(resolv);
|
||||
event_free(resolv);
|
||||
out1:
|
||||
close(fd);
|
||||
return err;
|
||||
@ -2786,12 +2786,12 @@ evdns_nameserver_ip_add_line(const char *ips) {
|
||||
addr = ips;
|
||||
while (ISDIGIT(*ips) || *ips == '.' || *ips == ':')
|
||||
++ips;
|
||||
buf = malloc(ips-addr+1);
|
||||
buf = event_malloc(ips-addr+1);
|
||||
if (!buf) return 4;
|
||||
memcpy(buf, addr, ips-addr);
|
||||
buf[ips-addr] = '\0';
|
||||
r = evdns_nameserver_ip_add(buf);
|
||||
free(buf);
|
||||
event_free(buf);
|
||||
if (r) return r;
|
||||
}
|
||||
return 0;
|
||||
@ -2824,7 +2824,7 @@ load_nameservers_with_getnetworkparams(void)
|
||||
goto done;
|
||||
}
|
||||
|
||||
buf = malloc(size);
|
||||
buf = event_malloc(size);
|
||||
if (!buf) { status = 4; goto done; }
|
||||
fixed = buf;
|
||||
r = fn(fixed, &size);
|
||||
@ -2833,8 +2833,8 @@ load_nameservers_with_getnetworkparams(void)
|
||||
goto done;
|
||||
}
|
||||
if (r != ERROR_SUCCESS) {
|
||||
free(buf);
|
||||
buf = malloc(size);
|
||||
event_free(buf);
|
||||
buf = event_malloc(size);
|
||||
if (!buf) { status = 4; goto done; }
|
||||
fixed = buf;
|
||||
r = fn(fixed, &size);
|
||||
@ -2870,7 +2870,7 @@ load_nameservers_with_getnetworkparams(void)
|
||||
|
||||
done:
|
||||
if (buf)
|
||||
free(buf);
|
||||
event_free(buf);
|
||||
if (handle)
|
||||
FreeLibrary(handle);
|
||||
return status;
|
||||
@ -2886,7 +2886,7 @@ config_nameserver_from_reg_key(HKEY key, const char *subkey)
|
||||
if (RegQueryValueEx(key, subkey, 0, &type, NULL, &bufsz)
|
||||
!= ERROR_MORE_DATA)
|
||||
return -1;
|
||||
if (!(buf = malloc(bufsz)))
|
||||
if (!(buf = event_malloc(bufsz)))
|
||||
return -1;
|
||||
|
||||
if (RegQueryValueEx(key, subkey, 0, &type, (LPBYTE)buf, &bufsz)
|
||||
@ -2894,7 +2894,7 @@ config_nameserver_from_reg_key(HKEY key, const char *subkey)
|
||||
status = evdns_nameserver_ip_add_line(buf);
|
||||
}
|
||||
|
||||
free(buf);
|
||||
event_free(buf);
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -3022,7 +3022,7 @@ evdns_shutdown(int fail_requests)
|
||||
(void) event_del(&server->event);
|
||||
if (server->state == 0)
|
||||
(void) event_del(&server->timeout_event);
|
||||
free(server);
|
||||
event_free(server);
|
||||
if (server_next == server_head)
|
||||
break;
|
||||
}
|
||||
@ -3032,9 +3032,9 @@ evdns_shutdown(int fail_requests)
|
||||
if (global_search_state) {
|
||||
for (dom = global_search_state->head; dom; dom = dom_next) {
|
||||
dom_next = dom->next;
|
||||
free(dom);
|
||||
event_free(dom);
|
||||
}
|
||||
free(global_search_state);
|
||||
event_free(global_search_state);
|
||||
global_search_state = NULL;
|
||||
}
|
||||
evdns_log_fn = NULL;
|
||||
|
@ -34,6 +34,7 @@ extern "C" {
|
||||
#include "config.h"
|
||||
#include "min_heap.h"
|
||||
#include "evsignal.h"
|
||||
#include "mm-internal.h"
|
||||
|
||||
struct eventop {
|
||||
const char *name;
|
||||
|
96
event.c
96
event.c
@ -172,7 +172,7 @@ event_base_new(void)
|
||||
int i;
|
||||
struct event_base *base;
|
||||
|
||||
if ((base = calloc(1, sizeof(struct event_base))) == NULL)
|
||||
if ((base = event_calloc(1, sizeof(struct event_base))) == NULL)
|
||||
event_err(1, "%s: calloc");
|
||||
|
||||
event_sigcb = NULL;
|
||||
@ -242,12 +242,12 @@ event_base_free(struct event_base *base)
|
||||
min_heap_dtor(&base->timeheap);
|
||||
|
||||
for (i = 0; i < base->nactivequeues; ++i)
|
||||
free(base->activequeues[i]);
|
||||
free(base->activequeues);
|
||||
event_free(base->activequeues[i]);
|
||||
event_free(base->activequeues);
|
||||
|
||||
assert(TAILQ_EMPTY(&base->eventqueue));
|
||||
|
||||
free(base);
|
||||
event_free(base);
|
||||
}
|
||||
|
||||
/* reinitialized the event base after a fork */
|
||||
@ -293,20 +293,21 @@ event_base_priority_init(struct event_base *base, int npriorities)
|
||||
|
||||
if (base->nactivequeues && npriorities != base->nactivequeues) {
|
||||
for (i = 0; i < base->nactivequeues; ++i) {
|
||||
free(base->activequeues[i]);
|
||||
event_free(base->activequeues[i]);
|
||||
}
|
||||
free(base->activequeues);
|
||||
event_free(base->activequeues);
|
||||
}
|
||||
|
||||
/* Allocate our priority queues */
|
||||
base->nactivequeues = npriorities;
|
||||
base->activequeues = (struct event_list **)calloc(base->nactivequeues,
|
||||
base->activequeues = (struct event_list **)event_calloc(
|
||||
base->nactivequeues,
|
||||
npriorities * sizeof(struct event_list *));
|
||||
if (base->activequeues == NULL)
|
||||
event_err(1, "%s: calloc", __func__);
|
||||
|
||||
for (i = 0; i < base->nactivequeues; ++i) {
|
||||
base->activequeues[i] = malloc(sizeof(struct event_list));
|
||||
base->activequeues[i] = event_malloc(sizeof(struct event_list));
|
||||
if (base->activequeues[i] == NULL)
|
||||
event_err(1, "%s: malloc", __func__);
|
||||
TAILQ_INIT(base->activequeues[i]);
|
||||
@ -524,7 +525,7 @@ event_once_cb(int fd, short events, void *arg)
|
||||
struct event_once *eonce = arg;
|
||||
|
||||
(*eonce->cb)(fd, events, eonce->arg);
|
||||
free(eonce);
|
||||
event_free(eonce);
|
||||
}
|
||||
|
||||
/* not threadsafe, event scheduled once. */
|
||||
@ -548,7 +549,7 @@ event_base_once(struct event_base *base, int fd, short events,
|
||||
if (events & EV_SIGNAL)
|
||||
return (-1);
|
||||
|
||||
if ((eonce = calloc(1, sizeof(struct event_once))) == NULL)
|
||||
if ((eonce = event_calloc(1, sizeof(struct event_once))) == NULL)
|
||||
return (-1);
|
||||
|
||||
eonce->cb = callback;
|
||||
@ -567,7 +568,7 @@ event_base_once(struct event_base *base, int fd, short events,
|
||||
event_set(&eonce->ev, fd, events, event_once_cb, eonce);
|
||||
} else {
|
||||
/* Bad event combination */
|
||||
free(eonce);
|
||||
event_free(eonce);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@ -575,7 +576,7 @@ event_base_once(struct event_base *base, int fd, short events,
|
||||
if (res == 0)
|
||||
res = event_add(&eonce->ev, tv);
|
||||
if (res != 0) {
|
||||
free(eonce);
|
||||
event_free(eonce);
|
||||
return (res);
|
||||
}
|
||||
|
||||
@ -973,3 +974,74 @@ event_get_method(void)
|
||||
{
|
||||
return (current_base->evsel->name);
|
||||
}
|
||||
|
||||
static void *(*_event_malloc_fn)(size_t sz) = NULL;
|
||||
static void *(*_event_realloc_fn)(void *p, size_t sz) = NULL;
|
||||
static void (*_event_free_fn)(void *p) = NULL;
|
||||
|
||||
void *
|
||||
event_malloc(size_t sz)
|
||||
{
|
||||
if (_event_malloc_fn)
|
||||
return _event_malloc_fn(sz);
|
||||
else
|
||||
return malloc(sz);
|
||||
}
|
||||
|
||||
void *
|
||||
event_calloc(size_t count, size_t size)
|
||||
{
|
||||
if (_event_malloc_fn) {
|
||||
size_t sz = count * size;
|
||||
void *p = _event_malloc_fn(sz);
|
||||
if (p)
|
||||
memset(p, 0, sz);
|
||||
return p;
|
||||
} else
|
||||
return calloc(count, size);
|
||||
}
|
||||
|
||||
char *
|
||||
event_strdup(const char *str)
|
||||
{
|
||||
if (_event_malloc_fn) {
|
||||
size_t ln = strlen(str);
|
||||
void *p = _event_malloc_fn(ln+1);
|
||||
if (p)
|
||||
memcpy(p, str, ln+1);
|
||||
return p;
|
||||
} else
|
||||
#ifdef WIN32
|
||||
return _strdup(str);
|
||||
#else
|
||||
return strdup(str);
|
||||
#endif
|
||||
}
|
||||
|
||||
void *
|
||||
event_realloc(void *ptr, size_t sz)
|
||||
{
|
||||
if (_event_realloc_fn)
|
||||
return _event_realloc_fn(ptr, sz);
|
||||
else
|
||||
return realloc(ptr, sz);
|
||||
}
|
||||
|
||||
void
|
||||
event_free(void *ptr)
|
||||
{
|
||||
if (_event_realloc_fn)
|
||||
_event_free_fn(ptr);
|
||||
else
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void
|
||||
event_set_mem_functions(void *(*malloc_fn)(size_t sz),
|
||||
void *(*realloc_fn)(void *ptr, size_t sz),
|
||||
void (*free_fn)(void *ptr))
|
||||
{
|
||||
_event_malloc_fn = malloc_fn;
|
||||
_event_realloc_fn = realloc_fn;
|
||||
_event_free_fn = free_fn;
|
||||
}
|
||||
|
21
event.h
21
event.h
@ -1105,6 +1105,27 @@ int evtag_unmarshal_string(struct evbuffer *evbuf, ev_uint8_t need_tag,
|
||||
int evtag_unmarshal_timeval(struct evbuffer *evbuf, ev_uint8_t need_tag,
|
||||
struct timeval *ptv);
|
||||
|
||||
/**
|
||||
Override the functions that libevent uses for memory management.
|
||||
|
||||
Usually, libevent uses the standard libc functions malloc, realloc, and
|
||||
free to allocate memory. Passing replacements for those functions to
|
||||
event_set_mem_functions() overrides this behavior. To restore the default
|
||||
behavior, pass NULLs as the arguments to this function.
|
||||
|
||||
Note that all memory returned from libevent will be allocated by the
|
||||
replacement functions rather than by malloc() and realloc(). Thus, if you
|
||||
have replaced those functions, it may not be appropriate to free() memory
|
||||
that you get from libevent.
|
||||
|
||||
@param malloc_fn A replacement for malloc.
|
||||
@param realloc_fn A replacement for realloc
|
||||
@param free_fn A replacement for free.
|
||||
**/
|
||||
void event_set_mem_functions(void *(*malloc_fn)(size_t sz),
|
||||
void *(*realloc_fn)(void *ptr, size_t sz),
|
||||
void (*free_fn)(void *ptr));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -63,6 +63,7 @@
|
||||
|
||||
#include "event.h"
|
||||
#include "log.h"
|
||||
#include "mm-internal.h"
|
||||
|
||||
int decode_int(uint32_t *pnumber, struct evbuffer *evbuf);
|
||||
|
||||
@ -347,7 +348,7 @@ evtag_unmarshal_string(struct evbuffer *evbuf, uint8_t need_tag,
|
||||
if (evtag_unmarshal(evbuf, &tag, _buf) == -1 || tag != need_tag)
|
||||
return (-1);
|
||||
|
||||
*pstring = calloc(EVBUFFER_LENGTH(_buf) + 1, 1);
|
||||
*pstring = event_calloc(EVBUFFER_LENGTH(_buf) + 1, 1);
|
||||
if (*pstring == NULL)
|
||||
event_err(1, "%s: calloc", __func__);
|
||||
evbuffer_remove(_buf, *pstring, EVBUFFER_LENGTH(_buf));
|
||||
|
14
evport.c
14
evport.c
@ -148,21 +148,21 @@ evport_init(struct event_base *base)
|
||||
if (getenv("EVENT_NOEVPORT"))
|
||||
return (NULL);
|
||||
|
||||
if (!(evpd = calloc(1, sizeof(struct evport_data))))
|
||||
if (!(evpd = event_calloc(1, sizeof(struct evport_data))))
|
||||
return (NULL);
|
||||
|
||||
if ((evpd->ed_port = port_create()) == -1) {
|
||||
free(evpd);
|
||||
event_free(evpd);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize file descriptor structure
|
||||
*/
|
||||
evpd->ed_fds = calloc(DEFAULT_NFDS, sizeof(struct fd_info));
|
||||
evpd->ed_fds = event_calloc(DEFAULT_NFDS, sizeof(struct fd_info));
|
||||
if (evpd->ed_fds == NULL) {
|
||||
close(evpd->ed_port);
|
||||
free(evpd);
|
||||
event_free(evpd);
|
||||
return (NULL);
|
||||
}
|
||||
evpd->ed_nevents = DEFAULT_NFDS;
|
||||
@ -245,7 +245,7 @@ grow(struct evport_data *epdp, int factor)
|
||||
|
||||
check_evportop(epdp);
|
||||
|
||||
tmp = realloc(epdp->ed_fds, sizeof(struct fd_info) * newsize);
|
||||
tmp = event_realloc(epdp->ed_fds, sizeof(struct fd_info) * newsize);
|
||||
if (NULL == tmp)
|
||||
return -1;
|
||||
epdp->ed_fds = tmp;
|
||||
@ -530,6 +530,6 @@ evport_dealloc(struct event_base *base, void *arg)
|
||||
close(evpd->ed_port);
|
||||
|
||||
if (evpd->ed_fds)
|
||||
free(evpd->ed_fds);
|
||||
free(evpd);
|
||||
event_free(evpd->ed_fds);
|
||||
event_free(evpd);
|
||||
}
|
||||
|
33
evrpc.c
33
evrpc.c
@ -60,11 +60,12 @@
|
||||
#include "evhttp.h"
|
||||
#include "evutil.h"
|
||||
#include "log.h"
|
||||
#include "mm-internal.h"
|
||||
|
||||
struct evrpc_base *
|
||||
evrpc_init(struct evhttp *http_server)
|
||||
{
|
||||
struct evrpc_base* base = calloc(1, sizeof(struct evrpc_base));
|
||||
struct evrpc_base* base = event_calloc(1, sizeof(struct evrpc_base));
|
||||
if (base == NULL)
|
||||
return (NULL);
|
||||
|
||||
@ -94,7 +95,7 @@ evrpc_free(struct evrpc_base *base)
|
||||
while ((hook = TAILQ_FIRST(&base->output_hooks)) != NULL) {
|
||||
assert(evrpc_remove_hook(base, OUTPUT, hook));
|
||||
}
|
||||
free(base);
|
||||
event_free(base);
|
||||
}
|
||||
|
||||
void *
|
||||
@ -117,7 +118,7 @@ evrpc_add_hook(void *vbase,
|
||||
assert(hook_type == INPUT || hook_type == OUTPUT);
|
||||
}
|
||||
|
||||
hook = calloc(1, sizeof(struct evrpc_hook));
|
||||
hook = event_calloc(1, sizeof(struct evrpc_hook));
|
||||
assert(hook != NULL);
|
||||
|
||||
hook->process = cb;
|
||||
@ -134,7 +135,7 @@ evrpc_remove_hook_internal(struct evrpc_hook_list *head, void *handle)
|
||||
TAILQ_FOREACH(hook, head, next) {
|
||||
if (hook == handle) {
|
||||
TAILQ_REMOVE(head, hook, next);
|
||||
free(hook);
|
||||
event_free(hook);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
@ -195,7 +196,7 @@ evrpc_construct_uri(const char *uri)
|
||||
int constructed_uri_len;
|
||||
|
||||
constructed_uri_len = strlen(EVRPC_URI_PREFIX) + strlen(uri) + 1;
|
||||
if ((constructed_uri = malloc(constructed_uri_len)) == NULL)
|
||||
if ((constructed_uri = event_malloc(constructed_uri_len)) == NULL)
|
||||
event_err(1, "%s: failed to register rpc at %s",
|
||||
__func__, uri);
|
||||
memcpy(constructed_uri, EVRPC_URI_PREFIX, strlen(EVRPC_URI_PREFIX));
|
||||
@ -222,7 +223,7 @@ evrpc_register_rpc(struct evrpc_base *base, struct evrpc *rpc,
|
||||
evrpc_request_cb,
|
||||
rpc);
|
||||
|
||||
free(constructed_uri);
|
||||
event_free(constructed_uri);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -244,15 +245,15 @@ evrpc_unregister_rpc(struct evrpc_base *base, const char *name)
|
||||
}
|
||||
TAILQ_REMOVE(&base->registered_rpcs, rpc, next);
|
||||
|
||||
free((char *)rpc->uri);
|
||||
free(rpc);
|
||||
event_free((char *)rpc->uri);
|
||||
event_free(rpc);
|
||||
|
||||
registered_uri = evrpc_construct_uri(name);
|
||||
|
||||
/* remove the http server callback */
|
||||
assert(evhttp_del_cb(base->http_server, registered_uri) == 0);
|
||||
|
||||
free(registered_uri);
|
||||
event_free(registered_uri);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -276,7 +277,7 @@ evrpc_request_cb(struct evhttp_request *req, void *arg)
|
||||
req, req->input_buffer) == -1)
|
||||
goto error;
|
||||
|
||||
rpc_state = calloc(1, sizeof(struct evrpc_req_generic));
|
||||
rpc_state = event_calloc(1, sizeof(struct evrpc_req_generic));
|
||||
if (rpc_state == NULL)
|
||||
goto error;
|
||||
|
||||
@ -324,7 +325,7 @@ evrpc_reqstate_free(struct evrpc_req_generic* rpc_state)
|
||||
rpc->request_free(rpc_state->request);
|
||||
if (rpc_state->reply != NULL)
|
||||
rpc->reply_free(rpc_state->reply);
|
||||
free(rpc_state);
|
||||
event_free(rpc_state);
|
||||
}
|
||||
}
|
||||
|
||||
@ -377,7 +378,7 @@ static int evrpc_schedule_request(struct evhttp_connection *connection,
|
||||
struct evrpc_pool *
|
||||
evrpc_pool_new(struct event_base *base)
|
||||
{
|
||||
struct evrpc_pool *pool = calloc(1, sizeof(struct evrpc_pool));
|
||||
struct evrpc_pool *pool = event_calloc(1, sizeof(struct evrpc_pool));
|
||||
if (pool == NULL)
|
||||
return (NULL);
|
||||
|
||||
@ -396,8 +397,8 @@ evrpc_pool_new(struct event_base *base)
|
||||
static void
|
||||
evrpc_request_wrapper_free(struct evrpc_request_wrapper *request)
|
||||
{
|
||||
free(request->name);
|
||||
free(request);
|
||||
event_free(request->name);
|
||||
event_free(request);
|
||||
}
|
||||
|
||||
void
|
||||
@ -426,7 +427,7 @@ evrpc_pool_free(struct evrpc_pool *pool)
|
||||
assert(evrpc_remove_hook(pool, OUTPUT, hook));
|
||||
}
|
||||
|
||||
free(pool);
|
||||
event_free(pool);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -539,7 +540,7 @@ evrpc_schedule_request(struct evhttp_connection *connection,
|
||||
|
||||
/* start the request over the connection */
|
||||
res = evhttp_make_request(connection, req, EVHTTP_REQ_POST, uri);
|
||||
free(uri);
|
||||
event_free(uri);
|
||||
|
||||
if (res == -1)
|
||||
goto error;
|
||||
|
120
http.c
120
http.c
@ -88,12 +88,12 @@
|
||||
#include "evutil.h"
|
||||
#include "log.h"
|
||||
#include "http-internal.h"
|
||||
#include "mm-internal.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#define snprintf _snprintf
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#define strdup _strdup
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETADDRINFO
|
||||
@ -119,7 +119,7 @@ fake_getaddrinfo(const char *hostname, struct addrinfo *ai)
|
||||
ai->ai_socktype = SOCK_STREAM;
|
||||
ai->ai_protocol = 0;
|
||||
ai->ai_addrlen = sizeof(struct sockaddr_in);
|
||||
if (NULL == (ai->ai_addr = malloc(ai->ai_addrlen)))
|
||||
if (NULL == (ai->ai_addr = event_malloc(ai->ai_addrlen)))
|
||||
return (-1);
|
||||
sa = (struct sockaddr_in*)ai->ai_addr;
|
||||
memset(sa, 0, ai->ai_addrlen);
|
||||
@ -136,7 +136,7 @@ fake_getaddrinfo(const char *hostname, struct addrinfo *ai)
|
||||
static void
|
||||
fake_freeaddrinfo(struct addrinfo *ai)
|
||||
{
|
||||
free(ai->ai_addr);
|
||||
event_free(ai->ai_addr);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -230,7 +230,7 @@ evhttp_htmlescape(const char *html)
|
||||
for (i = 0; i < old_size; ++i)
|
||||
new_size += strlen(html_replace(html[i]));
|
||||
|
||||
p = escaped_html = malloc(new_size + 1);
|
||||
p = escaped_html = event_malloc(new_size + 1);
|
||||
if (escaped_html == NULL)
|
||||
event_err(1, "%s: malloc(%d)", __func__, new_size + 1);
|
||||
for (i = 0; i < old_size; ++i) {
|
||||
@ -526,7 +526,7 @@ evhttp_connection_incoming_fail(struct evhttp_request *req,
|
||||
default: /* xxx: probably should just error on default */
|
||||
/* the callback looks at the uri to determine errors */
|
||||
if (req->uri) {
|
||||
free(req->uri);
|
||||
event_free(req->uri);
|
||||
req->uri = NULL;
|
||||
}
|
||||
|
||||
@ -692,12 +692,12 @@ evhttp_handle_chunked_read(struct evhttp_request *req, struct evbuffer *buf)
|
||||
break;
|
||||
/* the last chunk is on a new line? */
|
||||
if (strlen(p) == 0) {
|
||||
free(p);
|
||||
event_free(p);
|
||||
continue;
|
||||
}
|
||||
req->ntoread = strtol(p, &endp, 16);
|
||||
error = *p == '\0' || (*endp != '\0' && *endp != ' ');
|
||||
free(p);
|
||||
event_free(p);
|
||||
if (error) {
|
||||
/* could not get chunk size */
|
||||
return (-1);
|
||||
@ -847,10 +847,10 @@ evhttp_connection_free(struct evhttp_connection *evcon)
|
||||
EVUTIL_CLOSESOCKET(evcon->fd);
|
||||
|
||||
if (evcon->bind_address != NULL)
|
||||
free(evcon->bind_address);
|
||||
event_free(evcon->bind_address);
|
||||
|
||||
if (evcon->address != NULL)
|
||||
free(evcon->address);
|
||||
event_free(evcon->address);
|
||||
|
||||
if (evcon->input_buffer != NULL)
|
||||
evbuffer_free(evcon->input_buffer);
|
||||
@ -858,7 +858,7 @@ evhttp_connection_free(struct evhttp_connection *evcon)
|
||||
if (evcon->output_buffer != NULL)
|
||||
evbuffer_free(evcon->output_buffer);
|
||||
|
||||
free(evcon);
|
||||
event_free(evcon);
|
||||
}
|
||||
|
||||
void
|
||||
@ -867,8 +867,8 @@ evhttp_connection_set_local_address(struct evhttp_connection *evcon,
|
||||
{
|
||||
assert(evcon->state == EVCON_DISCONNECTED);
|
||||
if (evcon->bind_address)
|
||||
free(evcon->bind_address);
|
||||
if ((evcon->bind_address = strdup(address)) == NULL)
|
||||
event_free(evcon->bind_address);
|
||||
if ((evcon->bind_address = event_strdup(address)) == NULL)
|
||||
event_err(1, "%s: strdup", __func__);
|
||||
}
|
||||
|
||||
@ -1067,7 +1067,7 @@ evhttp_parse_response_line(struct evhttp_request *req, char *line)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if ((req->response_code_line = strdup(readable)) == NULL)
|
||||
if ((req->response_code_line = event_strdup(readable)) == NULL)
|
||||
event_err(1, "%s: strdup", __func__);
|
||||
|
||||
return (0);
|
||||
@ -1118,7 +1118,7 @@ evhttp_parse_request_line(struct evhttp_request *req, char *line)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if ((req->uri = strdup(uri)) == NULL) {
|
||||
if ((req->uri = event_strdup(uri)) == NULL) {
|
||||
event_debug(("%s: evhttp_decode_uri", __func__));
|
||||
return (-1);
|
||||
}
|
||||
@ -1152,9 +1152,9 @@ evhttp_clear_headers(struct evkeyvalq *headers)
|
||||
header != NULL;
|
||||
header = TAILQ_FIRST(headers)) {
|
||||
TAILQ_REMOVE(headers, header, next);
|
||||
free(header->key);
|
||||
free(header->value);
|
||||
free(header);
|
||||
event_free(header->key);
|
||||
event_free(header->value);
|
||||
event_free(header);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1178,9 +1178,9 @@ evhttp_remove_header(struct evkeyvalq *headers, const char *key)
|
||||
|
||||
/* Free and remove the header that we found */
|
||||
TAILQ_REMOVE(headers, header, next);
|
||||
free(header->key);
|
||||
free(header->value);
|
||||
free(header);
|
||||
event_free(header->key);
|
||||
event_free(header->value);
|
||||
event_free(header);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -1200,19 +1200,19 @@ evhttp_add_header(struct evkeyvalq *headers,
|
||||
return (-1);
|
||||
}
|
||||
|
||||
header = calloc(1, sizeof(struct evkeyval));
|
||||
header = event_calloc(1, sizeof(struct evkeyval));
|
||||
if (header == NULL) {
|
||||
event_warn("%s: calloc", __func__);
|
||||
return (-1);
|
||||
}
|
||||
if ((header->key = strdup(key)) == NULL) {
|
||||
free(header);
|
||||
if ((header->key = event_strdup(key)) == NULL) {
|
||||
event_free(header);
|
||||
event_warn("%s: strdup", __func__);
|
||||
return (-1);
|
||||
}
|
||||
if ((header->value = strdup(value)) == NULL) {
|
||||
free(header->key);
|
||||
free(header);
|
||||
if ((header->value = event_strdup(value)) == NULL) {
|
||||
event_free(header->key);
|
||||
event_free(header);
|
||||
event_warn("%s: strdup", __func__);
|
||||
return (-1);
|
||||
}
|
||||
@ -1244,7 +1244,7 @@ evhttp_parse_lines(struct evhttp_request *req, struct evbuffer* buffer)
|
||||
|
||||
if (*line == '\0') { /* Last header - Done */
|
||||
done = 1;
|
||||
free (line);
|
||||
event_free(line);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1276,13 +1276,13 @@ evhttp_parse_lines(struct evhttp_request *req, struct evbuffer* buffer)
|
||||
goto error;
|
||||
}
|
||||
|
||||
free (line);
|
||||
event_free(line);
|
||||
}
|
||||
|
||||
return (done);
|
||||
|
||||
error:
|
||||
free (line);
|
||||
event_free(line);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@ -1432,7 +1432,7 @@ evhttp_connection_new(const char *address, unsigned short port)
|
||||
|
||||
event_debug(("Attempting connection to %s:%d\n", address, port));
|
||||
|
||||
if ((evcon = calloc(1, sizeof(struct evhttp_connection))) == NULL) {
|
||||
if ((evcon = event_calloc(1, sizeof(struct evhttp_connection))) == NULL) {
|
||||
event_warn("%s: calloc failed", __func__);
|
||||
goto error;
|
||||
}
|
||||
@ -1443,7 +1443,7 @@ evhttp_connection_new(const char *address, unsigned short port)
|
||||
evcon->timeout = -1;
|
||||
evcon->retry_cnt = evcon->retry_max = 0;
|
||||
|
||||
if ((evcon->address = strdup(address)) == NULL) {
|
||||
if ((evcon->address = event_strdup(address)) == NULL) {
|
||||
event_warn("%s: strdup failed", __func__);
|
||||
goto error;
|
||||
}
|
||||
@ -1555,8 +1555,8 @@ evhttp_make_request(struct evhttp_connection *evcon,
|
||||
req->kind = EVHTTP_REQUEST;
|
||||
req->type = type;
|
||||
if (req->uri != NULL)
|
||||
free(req->uri);
|
||||
if ((req->uri = strdup(uri)) == NULL)
|
||||
event_free(req->uri);
|
||||
if ((req->uri = event_strdup(uri)) == NULL)
|
||||
event_err(1, "%s: strdup", __func__);
|
||||
|
||||
/* Set the protocol version if it is not supplied */
|
||||
@ -1743,8 +1743,8 @@ evhttp_response_code(struct evhttp_request *req, int code, const char *reason)
|
||||
req->kind = EVHTTP_RESPONSE;
|
||||
req->response_code = code;
|
||||
if (req->response_code_line != NULL)
|
||||
free(req->response_code_line);
|
||||
req->response_code_line = strdup(reason);
|
||||
event_free(req->response_code_line);
|
||||
req->response_code_line = event_strdup(reason);
|
||||
}
|
||||
|
||||
void
|
||||
@ -1805,7 +1805,7 @@ evhttp_encode_uri(const char *uri)
|
||||
}
|
||||
}
|
||||
evbuffer_add(buf, "", 1);
|
||||
p = strdup((char *)EVBUFFER_DATA(buf));
|
||||
p = event_strdup((char *)EVBUFFER_DATA(buf));
|
||||
evbuffer_free(buf);
|
||||
|
||||
return (p);
|
||||
@ -1817,7 +1817,7 @@ evhttp_decode_uri(const char *uri)
|
||||
char c, *ret;
|
||||
int i, j, in_query = 0;
|
||||
|
||||
ret = malloc(strlen(uri) + 1);
|
||||
ret = event_malloc(strlen(uri) + 1);
|
||||
if (ret == NULL)
|
||||
event_err(1, "%s: malloc(%d)", __func__, strlen(uri) + 1);
|
||||
|
||||
@ -1859,7 +1859,7 @@ evhttp_parse_query(const char *uri, struct evkeyvalq *headers)
|
||||
if (strchr(uri, '?') == NULL)
|
||||
return;
|
||||
|
||||
if ((line = strdup(uri)) == NULL)
|
||||
if ((line = event_strdup(uri)) == NULL)
|
||||
event_err(1, "%s: strdup", __func__);
|
||||
|
||||
|
||||
@ -1881,11 +1881,11 @@ evhttp_parse_query(const char *uri, struct evkeyvalq *headers)
|
||||
value = evhttp_decode_uri(value);
|
||||
event_debug(("Query Param: %s -> %s\n", key, value));
|
||||
evhttp_add_header(headers, key, value);
|
||||
free(value);
|
||||
event_free(value);
|
||||
}
|
||||
|
||||
error:
|
||||
free(line);
|
||||
event_free(line);
|
||||
}
|
||||
|
||||
static struct evhttp_cb *
|
||||
@ -1951,7 +1951,7 @@ evhttp_handle_request(struct evhttp_request *req, void *arg)
|
||||
|
||||
evbuffer_add_printf(buf, fmt, escaped_html);
|
||||
|
||||
free(escaped_html);
|
||||
event_free(escaped_html);
|
||||
|
||||
evhttp_send_page(req, buf);
|
||||
|
||||
@ -2007,7 +2007,7 @@ evhttp_new_object(void)
|
||||
{
|
||||
struct evhttp *http = NULL;
|
||||
|
||||
if ((http = calloc(1, sizeof(struct evhttp))) == NULL) {
|
||||
if ((http = event_calloc(1, sizeof(struct evhttp))) == NULL) {
|
||||
event_warn("%s: calloc", __func__);
|
||||
return (NULL);
|
||||
}
|
||||
@ -2040,7 +2040,7 @@ evhttp_start(const char *address, u_short port)
|
||||
struct evhttp *http = evhttp_new_object();
|
||||
|
||||
if (evhttp_bind_socket(http, address, port) == -1) {
|
||||
free(http);
|
||||
event_free(http);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@ -2065,11 +2065,11 @@ evhttp_free(struct evhttp* http)
|
||||
|
||||
while ((http_cb = TAILQ_FIRST(&http->callbacks)) != NULL) {
|
||||
TAILQ_REMOVE(&http->callbacks, http_cb, next);
|
||||
free(http_cb->what);
|
||||
free(http_cb);
|
||||
event_free(http_cb->what);
|
||||
event_free(http_cb);
|
||||
}
|
||||
|
||||
free(http);
|
||||
event_free(http);
|
||||
}
|
||||
|
||||
void
|
||||
@ -2084,10 +2084,10 @@ evhttp_set_cb(struct evhttp *http, const char *uri,
|
||||
{
|
||||
struct evhttp_cb *http_cb;
|
||||
|
||||
if ((http_cb = calloc(1, sizeof(struct evhttp_cb))) == NULL)
|
||||
if ((http_cb = event_calloc(1, sizeof(struct evhttp_cb))) == NULL)
|
||||
event_err(1, "%s: calloc", __func__);
|
||||
|
||||
http_cb->what = strdup(uri);
|
||||
http_cb->what = event_strdup(uri);
|
||||
http_cb->cb = cb;
|
||||
http_cb->cbarg = cbarg;
|
||||
|
||||
@ -2107,8 +2107,8 @@ evhttp_del_cb(struct evhttp *http, const char *uri)
|
||||
return (-1);
|
||||
|
||||
TAILQ_REMOVE(&http->callbacks, http_cb, next);
|
||||
free(http_cb->what);
|
||||
free(http_cb);
|
||||
event_free(http_cb->what);
|
||||
event_free(http_cb);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -2131,20 +2131,20 @@ evhttp_request_new(void (*cb)(struct evhttp_request *, void *), void *arg)
|
||||
struct evhttp_request *req = NULL;
|
||||
|
||||
/* Allocate request structure */
|
||||
if ((req = calloc(1, sizeof(struct evhttp_request))) == NULL) {
|
||||
if ((req = event_calloc(1, sizeof(struct evhttp_request))) == NULL) {
|
||||
event_warn("%s: calloc", __func__);
|
||||
goto error;
|
||||
}
|
||||
|
||||
req->kind = EVHTTP_RESPONSE;
|
||||
req->input_headers = calloc(1, sizeof(struct evkeyvalq));
|
||||
req->input_headers = event_calloc(1, sizeof(struct evkeyvalq));
|
||||
if (req->input_headers == NULL) {
|
||||
event_warn("%s: calloc", __func__);
|
||||
goto error;
|
||||
}
|
||||
TAILQ_INIT(req->input_headers);
|
||||
|
||||
req->output_headers = calloc(1, sizeof(struct evkeyvalq));
|
||||
req->output_headers = event_calloc(1, sizeof(struct evkeyvalq));
|
||||
if (req->output_headers == NULL) {
|
||||
event_warn("%s: calloc", __func__);
|
||||
goto error;
|
||||
@ -2176,17 +2176,17 @@ void
|
||||
evhttp_request_free(struct evhttp_request *req)
|
||||
{
|
||||
if (req->remote_host != NULL)
|
||||
free(req->remote_host);
|
||||
event_free(req->remote_host);
|
||||
if (req->uri != NULL)
|
||||
free(req->uri);
|
||||
event_free(req->uri);
|
||||
if (req->response_code_line != NULL)
|
||||
free(req->response_code_line);
|
||||
event_free(req->response_code_line);
|
||||
|
||||
evhttp_clear_headers(req->input_headers);
|
||||
free(req->input_headers);
|
||||
event_free(req->input_headers);
|
||||
|
||||
evhttp_clear_headers(req->output_headers);
|
||||
free(req->output_headers);
|
||||
event_free(req->output_headers);
|
||||
|
||||
if (req->input_buffer != NULL)
|
||||
evbuffer_free(req->input_buffer);
|
||||
@ -2194,7 +2194,7 @@ evhttp_request_free(struct evhttp_request *req)
|
||||
if (req->output_buffer != NULL)
|
||||
evbuffer_free(req->output_buffer);
|
||||
|
||||
free(req);
|
||||
event_free(req);
|
||||
}
|
||||
|
||||
void
|
||||
@ -2262,7 +2262,7 @@ evhttp_associate_new_request_with_connection(struct evhttp_connection *evcon)
|
||||
|
||||
req->kind = EVHTTP_REQUEST;
|
||||
|
||||
if ((req->remote_host = strdup(evcon->address)) == NULL)
|
||||
if ((req->remote_host = event_strdup(evcon->address)) == NULL)
|
||||
event_err(1, "%s: strdup", __func__);
|
||||
req->remote_port = evcon->port;
|
||||
|
||||
|
31
kqueue.c
31
kqueue.c
@ -60,6 +60,7 @@
|
||||
#include "event.h"
|
||||
#include "event-internal.h"
|
||||
#include "log.h"
|
||||
#include "event-internal.h"
|
||||
|
||||
#define EVLIST_X_KQINKERNEL 0x1000
|
||||
|
||||
@ -102,29 +103,29 @@ kq_init(struct event_base *base)
|
||||
if (getenv("EVENT_NOKQUEUE"))
|
||||
return (NULL);
|
||||
|
||||
if (!(kqueueop = calloc(1, sizeof(struct kqop))))
|
||||
if (!(kqueueop = event_calloc(1, sizeof(struct kqop))))
|
||||
return (NULL);
|
||||
|
||||
/* Initalize the kernel queue */
|
||||
|
||||
if ((kq = kqueue()) == -1) {
|
||||
event_warn("kqueue");
|
||||
free (kqueueop);
|
||||
event_free (kqueueop);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
kqueueop->kq = kq;
|
||||
|
||||
/* Initalize fields */
|
||||
kqueueop->changes = malloc(NEVENT * sizeof(struct kevent));
|
||||
kqueueop->changes = event_malloc(NEVENT * sizeof(struct kevent));
|
||||
if (kqueueop->changes == NULL) {
|
||||
free (kqueueop);
|
||||
event_free (kqueueop);
|
||||
return (NULL);
|
||||
}
|
||||
kqueueop->events = malloc(NEVENT * sizeof(struct kevent));
|
||||
kqueueop->events = event_malloc(NEVENT * sizeof(struct kevent));
|
||||
if (kqueueop->events == NULL) {
|
||||
free (kqueueop->changes);
|
||||
free (kqueueop);
|
||||
event_free (kqueueop->changes);
|
||||
event_free (kqueueop);
|
||||
return (NULL);
|
||||
}
|
||||
kqueueop->nevents = NEVENT;
|
||||
@ -143,9 +144,9 @@ kq_init(struct event_base *base)
|
||||
kqueueop->events[0].ident != -1 ||
|
||||
kqueueop->events[0].flags != EV_ERROR) {
|
||||
event_warn("%s: detected broken kqueue; not using.", __func__);
|
||||
free(kqueueop->changes);
|
||||
free(kqueueop->events);
|
||||
free(kqueueop);
|
||||
event_free(kqueueop->changes);
|
||||
event_free(kqueueop->events);
|
||||
event_free(kqueueop);
|
||||
close(kq);
|
||||
return (NULL);
|
||||
}
|
||||
@ -170,7 +171,7 @@ kq_insert(struct kqop *kqop, struct kevent *kev)
|
||||
|
||||
nevents *= 2;
|
||||
|
||||
newchange = realloc(kqop->changes,
|
||||
newchange = event_realloc(kqop->changes,
|
||||
nevents * sizeof(struct kevent));
|
||||
if (newchange == NULL) {
|
||||
event_warn("%s: malloc", __func__);
|
||||
@ -178,7 +179,7 @@ kq_insert(struct kqop *kqop, struct kevent *kev)
|
||||
}
|
||||
kqop->changes = newchange;
|
||||
|
||||
newresult = realloc(kqop->events,
|
||||
newresult = event_realloc(kqop->events,
|
||||
nevents * sizeof(struct kevent));
|
||||
|
||||
/*
|
||||
@ -411,11 +412,11 @@ kq_dealloc(struct event_base *base, void *arg)
|
||||
struct kqop *kqop = arg;
|
||||
|
||||
if (kqop->changes)
|
||||
free(kqop->changes);
|
||||
event_free(kqop->changes);
|
||||
if (kqop->events)
|
||||
free(kqop->events);
|
||||
event_free(kqop->events);
|
||||
if (kqop->kq)
|
||||
close(kqop->kq);
|
||||
memset(kqop, 0, sizeof(struct kqop));
|
||||
free(kqop);
|
||||
event_free(kqop);
|
||||
}
|
||||
|
20
poll.c
20
poll.c
@ -91,7 +91,7 @@ poll_init(struct event_base *base)
|
||||
if (getenv("EVENT_NOPOLL"))
|
||||
return (NULL);
|
||||
|
||||
if (!(pollop = calloc(1, sizeof(struct pollop))))
|
||||
if (!(pollop = event_calloc(1, sizeof(struct pollop))))
|
||||
return (NULL);
|
||||
|
||||
evsignal_init(base);
|
||||
@ -237,7 +237,7 @@ poll_add(void *arg, struct event *ev)
|
||||
tmp_event_count = pop->event_count * 2;
|
||||
|
||||
/* We need more file descriptors */
|
||||
tmp_event_set = realloc(pop->event_set,
|
||||
tmp_event_set = event_realloc(pop->event_set,
|
||||
tmp_event_count * sizeof(struct pollfd));
|
||||
if (tmp_event_set == NULL) {
|
||||
event_warn("realloc");
|
||||
@ -245,7 +245,7 @@ poll_add(void *arg, struct event *ev)
|
||||
}
|
||||
pop->event_set = tmp_event_set;
|
||||
|
||||
tmp_event_r_back = realloc(pop->event_r_back,
|
||||
tmp_event_r_back = event_realloc(pop->event_r_back,
|
||||
tmp_event_count * sizeof(struct event *));
|
||||
if (tmp_event_r_back == NULL) {
|
||||
/* event_set overallocated; that's okay. */
|
||||
@ -254,7 +254,7 @@ poll_add(void *arg, struct event *ev)
|
||||
}
|
||||
pop->event_r_back = tmp_event_r_back;
|
||||
|
||||
tmp_event_w_back = realloc(pop->event_w_back,
|
||||
tmp_event_w_back = event_realloc(pop->event_w_back,
|
||||
tmp_event_count * sizeof(struct event *));
|
||||
if (tmp_event_w_back == NULL) {
|
||||
/* event_set and event_r_back overallocated; that's
|
||||
@ -276,7 +276,7 @@ poll_add(void *arg, struct event *ev)
|
||||
while (new_count <= ev->ev_fd)
|
||||
new_count *= 2;
|
||||
tmp_idxplus1_by_fd =
|
||||
realloc(pop->idxplus1_by_fd, new_count * sizeof(int));
|
||||
event_realloc(pop->idxplus1_by_fd, new_count * sizeof(int));
|
||||
if (tmp_idxplus1_by_fd == NULL) {
|
||||
event_warn("realloc");
|
||||
return (-1);
|
||||
@ -377,14 +377,14 @@ poll_dealloc(struct event_base *base, void *arg)
|
||||
|
||||
evsignal_dealloc(base);
|
||||
if (pop->event_set)
|
||||
free(pop->event_set);
|
||||
event_free(pop->event_set);
|
||||
if (pop->event_r_back)
|
||||
free(pop->event_r_back);
|
||||
event_free(pop->event_r_back);
|
||||
if (pop->event_w_back)
|
||||
free(pop->event_w_back);
|
||||
event_free(pop->event_w_back);
|
||||
if (pop->idxplus1_by_fd)
|
||||
free(pop->idxplus1_by_fd);
|
||||
event_free(pop->idxplus1_by_fd);
|
||||
|
||||
memset(pop, 0, sizeof(struct pollop));
|
||||
free(pop);
|
||||
event_free(pop);
|
||||
}
|
||||
|
28
select.c
28
select.c
@ -98,7 +98,7 @@ select_init(struct event_base *base)
|
||||
if (getenv("EVENT_NOSELECT"))
|
||||
return (NULL);
|
||||
|
||||
if (!(sop = calloc(1, sizeof(struct selectop))))
|
||||
if (!(sop = event_calloc(1, sizeof(struct selectop))))
|
||||
return (NULL);
|
||||
|
||||
select_resize(sop, howmany(32 + 1, NFDBITS)*sizeof(fd_mask));
|
||||
@ -229,23 +229,23 @@ select_resize(struct selectop *sop, int fdsz)
|
||||
if (sop->event_readset_in)
|
||||
check_selectop(sop);
|
||||
|
||||
if ((readset_in = realloc(sop->event_readset_in, fdsz)) == NULL)
|
||||
if ((readset_in = event_realloc(sop->event_readset_in, fdsz)) == NULL)
|
||||
goto error;
|
||||
sop->event_readset_in = readset_in;
|
||||
if ((readset_out = realloc(sop->event_readset_out, fdsz)) == NULL)
|
||||
if ((readset_out = event_realloc(sop->event_readset_out, fdsz)) == NULL)
|
||||
goto error;
|
||||
sop->event_readset_out = readset_out;
|
||||
if ((writeset_in = realloc(sop->event_writeset_in, fdsz)) == NULL)
|
||||
if ((writeset_in = event_realloc(sop->event_writeset_in, fdsz)) == NULL)
|
||||
goto error;
|
||||
sop->event_writeset_in = writeset_in;
|
||||
if ((writeset_out = realloc(sop->event_writeset_out, fdsz)) == NULL)
|
||||
if ((writeset_out = event_realloc(sop->event_writeset_out, fdsz)) == NULL)
|
||||
goto error;
|
||||
sop->event_writeset_out = writeset_out;
|
||||
if ((r_by_fd = realloc(sop->event_r_by_fd,
|
||||
if ((r_by_fd = event_realloc(sop->event_r_by_fd,
|
||||
n_events*sizeof(struct event*))) == NULL)
|
||||
goto error;
|
||||
sop->event_r_by_fd = r_by_fd;
|
||||
if ((w_by_fd = realloc(sop->event_w_by_fd,
|
||||
if ((w_by_fd = event_realloc(sop->event_w_by_fd,
|
||||
n_events * sizeof(struct event*))) == NULL)
|
||||
goto error;
|
||||
sop->event_w_by_fd = w_by_fd;
|
||||
@ -355,18 +355,18 @@ select_dealloc(struct event_base *base, void *arg)
|
||||
|
||||
evsignal_dealloc(base);
|
||||
if (sop->event_readset_in)
|
||||
free(sop->event_readset_in);
|
||||
event_free(sop->event_readset_in);
|
||||
if (sop->event_writeset_in)
|
||||
free(sop->event_writeset_in);
|
||||
event_free(sop->event_writeset_in);
|
||||
if (sop->event_readset_out)
|
||||
free(sop->event_readset_out);
|
||||
event_free(sop->event_readset_out);
|
||||
if (sop->event_writeset_out)
|
||||
free(sop->event_writeset_out);
|
||||
event_free(sop->event_writeset_out);
|
||||
if (sop->event_r_by_fd)
|
||||
free(sop->event_r_by_fd);
|
||||
event_free(sop->event_r_by_fd);
|
||||
if (sop->event_w_by_fd)
|
||||
free(sop->event_w_by_fd);
|
||||
event_free(sop->event_w_by_fd);
|
||||
|
||||
memset(sop, 0, sizeof(struct selectop));
|
||||
free(sop);
|
||||
event_free(sop);
|
||||
}
|
||||
|
12
signal.c
12
signal.c
@ -144,7 +144,7 @@ evsignal_add(struct event *ev)
|
||||
event_debug(("%s: evsignal (%d) >= sh_old_max (%d), resizing",
|
||||
__func__, evsignal, sig->sh_old_max));
|
||||
sig->sh_old_max = evsignal + 1;
|
||||
p = realloc(sig->sh_old, sig->sh_old_max * sizeof *sig->sh_old);
|
||||
p = event_realloc(sig->sh_old, sig->sh_old_max * sizeof *sig->sh_old);
|
||||
if (p == NULL) {
|
||||
event_warn("realloc");
|
||||
return (-1);
|
||||
@ -153,7 +153,7 @@ evsignal_add(struct event *ev)
|
||||
}
|
||||
|
||||
/* allocate space for previous handler out of dynamic array */
|
||||
sig->sh_old[evsignal] = malloc(sizeof *sig->sh_old[evsignal]);
|
||||
sig->sh_old[evsignal] = event_malloc(sizeof *sig->sh_old[evsignal]);
|
||||
if (sig->sh_old[evsignal] == NULL) {
|
||||
event_warn("malloc");
|
||||
return (-1);
|
||||
@ -169,13 +169,13 @@ evsignal_add(struct event *ev)
|
||||
|
||||
if (sigaction(evsignal, &sa, sig->sh_old[evsignal]) == -1) {
|
||||
event_warn("sigaction");
|
||||
free(sig->sh_old[evsignal]);
|
||||
event_free(sig->sh_old[evsignal]);
|
||||
return (-1);
|
||||
}
|
||||
#else
|
||||
if ((sh = signal(evsignal, evsignal_handler)) == SIG_ERR) {
|
||||
event_warn("signal");
|
||||
free(sig->sh_old[evsignal]);
|
||||
event_free(sig->sh_old[evsignal]);
|
||||
return (-1);
|
||||
}
|
||||
*sig->sh_old[evsignal] = sh;
|
||||
@ -220,7 +220,7 @@ evsignal_del(struct event *ev)
|
||||
ret = -1;
|
||||
}
|
||||
#endif
|
||||
free(sh);
|
||||
event_free(sh);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -283,5 +283,5 @@ evsignal_dealloc(struct event_base *base)
|
||||
base->sig.sh_old_max = 0;
|
||||
|
||||
/* per index frees are handled in evsignal_del() */
|
||||
free(base->sig.sh_old);
|
||||
event_free(base->sig.sh_old);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user