Rename internal memory management functions from event_malloc() etc to mm_malloc() etc.
svn:r725
o Make name_from_addr() threadsafe in http.c
o Add new thread-safe interfaces to evdns functions.
o Make all event_tagging interfaces threadsafe.
+ o Rename internal memory management functions.
Changes in 1.4.0:
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
to_alloc <<= 1;
/* we get everything in one chunk */
- if ((chain = event_malloc(to_alloc)) == NULL)
+ if ((chain = mm_malloc(to_alloc)) == NULL)
return (NULL);
memset(chain, 0, EVBUFFER_CHAIN_SIZE);
{
struct evbuffer *buffer;
- buffer = event_calloc(1, sizeof(struct evbuffer));
+ buffer = mm_calloc(1, sizeof(struct evbuffer));
return (buffer);
}
struct evbuffer_chain *chain, *next;
for (chain = buffer->first; chain != NULL; chain = next) {
next = chain->next;
- event_free(chain);
+ mm_free(chain);
}
- event_free(buffer);
+ mm_free(buffer);
}
size_t
for (chain = buf->first; chain != NULL; chain = next) {
next = chain->next;
- event_free(chain);
+ mm_free(chain);
}
ZERO_CHAIN(buf);
next = chain->next;
len -= chain->off;
- event_free(chain);
+ mm_free(chain);
}
buf->first = chain;
tmp = chain;
chain = chain->next;
- event_free(tmp);
+ mm_free(tmp);
}
buf->first = chain;
size -= chain->off;
buffer += chain->off;
- event_free(chain);
+ mm_free(chain);
}
if (chain != NULL) {
return (NULL);
}
- if ((line = event_malloc(n_to_copy+1)) == NULL) {
+ if ((line = mm_malloc(n_to_copy+1)) == NULL) {
event_warn("%s: out of memory\n", __func__);
evbuffer_drain(buffer, n_to_copy + extra_drain);
return (NULL);
buf->previous_to_last->next = tmp;
buf->last = tmp;
- event_free(chain);
+ mm_free(chain);
return (0);
}
if (getenv("EVENT_NODEVPOLL"))
return (NULL);
- if (!(devpollop = event_calloc(1, sizeof(struct devpollop))))
+ if (!(devpollop = mm_calloc(1, sizeof(struct devpollop))))
return (NULL);
if (getrlimit(RLIMIT_NOFILE, &rl) == 0 &&
/* Initialize the kernel queue */
if ((dpfd = open("/dev/poll", O_RDWR)) == -1) {
event_warn("open: /dev/poll");
- event_free(devpollop);
+ mm_free(devpollop);
return (NULL);
}
devpollop->dpfd = dpfd;
/* Initialize fields */
- devpollop->events = event_calloc(nfiles, sizeof(struct pollfd));
+ devpollop->events = mm_calloc(nfiles, sizeof(struct pollfd));
if (devpollop->events == NULL) {
- event_free(devpollop);
+ mm_free(devpollop);
close(dpfd);
return (NULL);
}
devpollop->nevents = nfiles;
- devpollop->fds = event_calloc(nfiles, sizeof(struct evdevpoll));
+ devpollop->fds = mm_calloc(nfiles, sizeof(struct evdevpoll));
if (devpollop->fds == NULL) {
- event_free(devpollop->events);
- event_free(devpollop);
+ mm_free(devpollop->events);
+ mm_free(devpollop);
close(dpfd);
return (NULL);
}
devpollop->nfds = nfiles;
- devpollop->changes = event_calloc(nfiles, sizeof(struct pollfd));
+ devpollop->changes = mm_calloc(nfiles, sizeof(struct pollfd));
if (devpollop->changes == NULL) {
- event_free(devpollop->fds);
- event_free(devpollop->events);
- event_free(devpollop);
+ mm_free(devpollop->fds);
+ mm_free(devpollop->events);
+ mm_free(devpollop);
close(dpfd);
return (NULL);
}
while (nfds < max)
nfds <<= 1;
- fds = event_realloc(devpollop->fds, nfds * sizeof(struct evdevpoll));
+ fds = mm_realloc(devpollop->fds, nfds * sizeof(struct evdevpoll));
if (fds == NULL) {
event_warn("realloc");
return (-1);
evsignal_dealloc(base);
if (devpollop->fds)
- event_free(devpollop->fds);
+ mm_free(devpollop->fds);
if (devpollop->events)
- event_free(devpollop->events);
+ mm_free(devpollop->events);
if (devpollop->changes)
- event_free(devpollop->changes);
+ mm_free(devpollop->changes);
if (devpollop->dpfd >= 0)
close(devpollop->dpfd);
memset(devpollop, 0, sizeof(struct devpollop));
- event_free(devpollop);
+ mm_free(devpollop);
}
FD_CLOSEONEXEC(epfd);
- if (!(epollop = event_calloc(1, sizeof(struct epollop))))
+ if (!(epollop = mm_calloc(1, sizeof(struct epollop))))
return (NULL);
epollop->epfd = epfd;
/* Initalize fields */
- epollop->events = event_malloc(nfiles * sizeof(struct epoll_event));
+ epollop->events = mm_malloc(nfiles * sizeof(struct epoll_event));
if (epollop->events == NULL) {
- event_free(epollop);
+ mm_free(epollop);
return (NULL);
}
epollop->nevents = nfiles;
- epollop->fds = event_calloc(nfiles, sizeof(struct evepoll));
+ epollop->fds = mm_calloc(nfiles, sizeof(struct evepoll));
if (epollop->fds == NULL) {
- event_free(epollop->events);
- event_free(epollop);
+ mm_free(epollop->events);
+ mm_free(epollop);
return (NULL);
}
epollop->nfds = nfiles;
while (nfds < max)
nfds <<= 1;
- fds = event_realloc(epollop->fds, nfds * sizeof(struct evepoll));
+ fds = mm_realloc(epollop->fds, nfds * sizeof(struct evepoll));
if (fds == NULL) {
event_warn("realloc");
return (-1);
evsignal_dealloc(base);
if (epollop->fds)
- event_free(epollop->fds);
+ mm_free(epollop->fds);
if (epollop->events)
- event_free(epollop->events);
+ mm_free(epollop->events);
if (epollop->epfd >= 0)
close(epollop->epfd);
memset(epollop, 0, sizeof(struct epollop));
- event_free(epollop);
+ mm_free(epollop);
}
{
struct bufferevent *bufev;
- if ((bufev = event_calloc(1, sizeof(struct bufferevent))) == NULL)
+ if ((bufev = mm_calloc(1, sizeof(struct bufferevent))) == NULL)
return (NULL);
if ((bufev->input = evbuffer_new()) == NULL) {
- event_free(bufev);
+ mm_free(bufev);
return (NULL);
}
if ((bufev->output = evbuffer_new()) == NULL) {
evbuffer_free(bufev->input);
- event_free(bufev);
+ mm_free(bufev);
return (NULL);
}
evbuffer_free(bufev->input);
evbuffer_free(bufev->output);
- event_free(bufev);
+ mm_free(bufev);
}
/*
};
struct evdns_base {
- struct request *req_head, *req_waiting_head;
+ /* An array of n_req_heads circular lists for inflight requests.
+ * Each inflight request req is in req_heads[req->trans_id % n_req_heads].
+ */
+ struct request **req_heads;
+ /* A circular list of requests that we're waiting to send, but haven't
+ * sent yet because there are too many requests inflight */
+ struct request *req_waiting_head;
+ /* A circular list of nameservers. */
struct nameserver *server_head;
+ int n_req_heads;
struct event_base *event_base;
((struct server_request*) \
(((char*)(base_ptr) - OFFSET_OF(struct server_request, base))))
+#define REQ_HEAD(base, id) ((base)->req_heads[id % (base)->n_req_heads])
+
/* These are the timeout values for nameservers. If we find a nameserver is down */
/* we try to probe it at intervals as given below. Values are in seconds. */
static const struct timeval global_nameserver_timeouts[] = {{10, 0}, {60, 0}, {300, 0}, {900, 0}, {3600, 0}};
/* failure */
static struct request *
request_find_from_trans_id(struct evdns_base *base, u16 trans_id) {
- struct request *req = base->req_head, *const started_at = base->req_head;
+ struct request *req = REQ_HEAD(base, trans_id);
+ struct request *const started_at = req;
if (req) {
do {
nameserver_failed(struct nameserver *const ns, const char *msg) {
struct request *req, *started_at;
struct evdns_base *base = ns->base;
+ int i;
/* if this nameserver has already been marked as failed */
/* then don't do anything */
if (!ns->state) return;
/* trying to reassign requests to one */
if (!base->global_good_nameservers) return;
- req = started_at = base->req_head;
- if (req) {
- do {
- if (req->tx_count == 0 && req->ns == ns) {
- /* still waiting to go out, can be moved */
- /* to another server */
- req->ns = nameserver_pick(base);
- }
- req = req->next;
- } while (req != started_at);
+ for (i = 0; i < base->n_req_heads; ++i) {
+ req = started_at = base->req_heads[i];
+ if (req) {
+ do {
+ if (req->tx_count == 0 && req->ns == ns) {
+ /* still waiting to go out, can be moved */
+ /* to another server */
+ req->ns = nameserver_pick(base);
+ }
+ req = req->next;
+ } while (req != started_at);
+ }
}
}
if (!req->request_appended) {
/* need to free the request data on it's own */
- event_free(req->request);
+ mm_free(req->request);
} else {
/* the request data is appended onto the header */
/* so everything gets free()ed when we: */
}
- event_free(req);
+ mm_free(req);
evdns_requests_pump_waiting_queue(base);
}
req->ns = nameserver_pick(base);
request_trans_id_set(req, transaction_id_pick(base));
- evdns_request_insert(req, &base->req_head);
+ evdns_request_insert(req, &REQ_HEAD(base, req->trans_id));
evdns_request_transmit(req);
evdns_transmit(base);
}
/* a new request was issued so this request is finished and */
/* the user callback will be made when that request (or a */
/* child of it) finishes. */
- request_finished(req, &req->base->req_head);
+ request_finished(req, &REQ_HEAD(req->base, req->trans_id));
return;
}
}
/* all else failed. Pass the failure up */
reply_callback(req, 0, error, NULL);
- request_finished(req, &req->base->req_head);
+ request_finished(req, &REQ_HEAD(req->base, req->trans_id));
} else {
/* all ok, tell the user */
reply_callback(req, ttl, 0, reply);
nameserver_up(req->ns);
- request_finished(req, &req->base->req_head);
+ request_finished(req, &REQ_HEAD(req->base, req->trans_id));
}
}
if (flags & 0x8000) return -1; /* Must not be an answer. */
flags &= 0x0110; /* Only RD and CD get preserved. */
- server_req = event_malloc(sizeof(struct server_request));
+ server_req = mm_malloc(sizeof(struct server_request));
if (server_req == NULL) return -1;
memset(server_req, 0, sizeof(struct server_request));
server_req->base.flags = flags;
server_req->base.nquestions = 0;
- server_req->base.questions = event_malloc(sizeof(struct evdns_server_question *) * questions);
+ server_req->base.questions = mm_malloc(sizeof(struct evdns_server_question *) * questions);
if (server_req->base.questions == NULL)
goto err;
GET16(type);
GET16(class);
namelen = strlen(tmp_name);
- q = event_malloc(sizeof(struct evdns_server_question) + namelen);
+ q = mm_malloc(sizeof(struct evdns_server_question) + namelen);
if (!q)
goto err;
q->type = type;
if (server_req) {
if (server_req->base.questions) {
for (i = 0; i < server_req->base.nquestions; ++i)
- event_free(server_req->base.questions[i]);
- event_free(server_req->base.questions);
+ mm_free(server_req->base.questions[i]);
+ mm_free(server_req->base.questions);
}
- event_free(server_req);
+ mm_free(server_req);
}
return -1;
static u16
transaction_id_pick(struct evdns_base *base) {
for (;;) {
- const struct request *req, *started_at;
u16 trans_id = trans_id_function();
if (trans_id == 0xffff) continue;
/* now check to see if that id is already inflight */
- req = started_at = base->req_head;
- if (req) {
- do {
- if (req->trans_id == trans_id) break;
- req = req->next;
- } while (req != started_at);
- }
- /* we didn't find it, so this is a good id */
- if (req == started_at) return trans_id;
+ if (request_find_from_trans_id(base, trans_id) == NULL)
+ return trans_id;
}
}
{
int i;
for (i = 0; i < table->n_labels; ++i)
- event_free(table->labels[i].v);
+ mm_free(table->labels[i].v);
table->n_labels = 0;
}
int p;
if (table->n_labels == MAX_LABELS)
return (-1);
- v = event_strdup(label);
+ v = mm_strdup(label);
if (v == NULL)
return (-1);
p = table->n_labels++;
evdns_add_server_port_with_base(struct event_base *base, int socket, int is_tcp, evdns_request_callback_fn_type cb, void *user_data)
{
struct evdns_server_port *port;
- if (!(port = event_malloc(sizeof(struct evdns_server_port))))
+ if (!(port = mm_malloc(sizeof(struct evdns_server_port))))
return NULL;
memset(port, 0, sizeof(struct evdns_server_port));
while (*itemp) {
itemp = &((*itemp)->next);
}
- item = event_malloc(sizeof(struct server_reply_item));
+ item = mm_malloc(sizeof(struct server_reply_item));
if (!item)
return -1;
item->next = NULL;
- if (!(item->name = event_strdup(name))) {
- event_free(item);
+ if (!(item->name = mm_strdup(name))) {
+ mm_free(item);
return -1;
}
item->type = type;
item->data = NULL;
if (data) {
if (item->is_name) {
- if (!(item->data = event_strdup(data))) {
- event_free(item->name);
- event_free(item);
+ if (!(item->data = mm_strdup(data))) {
+ mm_free(item->name);
+ mm_free(item);
return -1;
}
item->datalen = (u16)-1;
} else {
- if (!(item->data = event_malloc(datalen))) {
- event_free(item->name);
- event_free(item);
+ if (!(item->data = mm_malloc(datalen))) {
+ mm_free(item->name);
+ mm_free(item);
return -1;
}
item->datalen = datalen;
req->response_len = j;
- if (!(req->response = event_malloc(req->response_len))) {
+ if (!(req->response = mm_malloc(req->response_len))) {
server_request_free_answers(req);
dnslabel_clear(&table);
return (-1);
victim = *list;
while (victim) {
next = victim->next;
- event_free(victim->name);
+ mm_free(victim->name);
if (victim->data)
- event_free(victim->data);
- event_free(victim);
+ mm_free(victim->data);
+ mm_free(victim);
victim = next;
}
*list = NULL;
int i, rc=1;
if (req->base.questions) {
for (i = 0; i < req->base.nquestions; ++i)
- event_free(req->base.questions[i]);
- event_free(req->base.questions);
+ mm_free(req->base.questions[i]);
+ mm_free(req->base.questions);
}
if (req->port) {
}
if (req->response) {
- event_free(req->response);
+ mm_free(req->response);
}
server_request_free_answers(req);
if (rc == 0) {
server_port_free(req->port);
- event_free(req);
+ mm_free(req);
return (1);
}
- event_free(req);
+ mm_free(req);
return (0);
}
if (req->tx_count >= req->base->global_max_retransmits) {
/* this request has failed */
reply_callback(req, 0, DNS_ERR_TIMEOUT, NULL);
- request_finished(req, &req->base->req_head);
+ request_finished(req, &REQ_HEAD(req->base, req->trans_id));
} else {
/* retransmit it */
evdns_request_transmit(req);
static int
evdns_transmit(struct evdns_base *base) {
char did_try_to_transmit = 0;
+ int i;
- if (base->req_head) {
- struct request *const started_at = base->req_head, *req = base->req_head;
- /* first transmit all the requests which are currently waiting */
- do {
- if (req->transmit_me) {
- did_try_to_transmit = 1;
- evdns_request_transmit(req);
- }
+ for (i = 0; i < base->n_req_heads; ++i) {
+ if (base->req_heads[i]) {
+ struct request *const started_at = base->req_heads[i], *req = started_at;
+ /* first transmit all the requests which are currently waiting */
+ do {
+ if (req->transmit_me) {
+ did_try_to_transmit = 1;
+ evdns_request_transmit(req);
+ }
- req = req->next;
- } while (req != started_at);
+ req = req->next;
+ } while (req != started_at);
+ }
}
return did_try_to_transmit;
evdns_base_clear_nameservers_and_suspend(struct evdns_base *base)
{
struct nameserver *server = base->server_head, *started_at = base->server_head;
- struct request *req = base->req_head, *req_started_at = base->req_head;
+ int i;
if (!server)
return 0;
(void) evtimer_del(&server->timeout_event);
if (server->socket >= 0)
CLOSE_SOCKET(server->socket);
- event_free(server);
+ mm_free(server);
if (next == started_at)
break;
server = next;
base->server_head = NULL;
base->global_good_nameservers = 0;
- while (req) {
- struct request *next = req->next;
- req->tx_count = req->reissue_count = 0;
- req->ns = NULL;
- /* ???? What to do about searches? */
- (void) evtimer_del(&req->timeout_event);
- req->trans_id = 0;
- req->transmit_me = 0;
-
- base->global_requests_waiting++;
- evdns_request_insert(req, &base->req_waiting_head);
- /* We want to insert these suspended elements at the front of
- * the waiting queue, since they were pending before any of
- * the waiting entries were added. This is a circular list,
- * so we can just shift the start back by one.*/
- base->req_waiting_head = base->req_waiting_head->prev;
-
- if (next == req_started_at)
- break;
- req = next;
+ for (i = 0; i < base->n_req_heads; ++i) {
+ struct request *req, *req_started_at;
+ req = req_started_at = base->req_heads[i];
+ while (req) {
+ struct request *next = req->next;
+ req->tx_count = req->reissue_count = 0;
+ req->ns = NULL;
+ /* ???? What to do about searches? */
+ (void) evtimer_del(&req->timeout_event);
+ req->trans_id = 0;
+ req->transmit_me = 0;
+
+ base->global_requests_waiting++;
+ evdns_request_insert(req, &base->req_waiting_head);
+ /* We want to insert these suspended elements at the front of
+ * the waiting queue, since they were pending before any of
+ * the waiting entries were added. This is a circular list,
+ * so we can just shift the start back by one.*/
+ base->req_waiting_head = base->req_waiting_head->prev;
+
+ if (next == req_started_at)
+ break;
+ req = next;
+ }
+ base->req_heads[i] = NULL;
}
- base->req_head = NULL;
+
base->global_requests_inflight = 0;
return 0;
} while (server != started_at);
}
- ns = (struct nameserver *) event_malloc(sizeof(struct nameserver));
+ ns = (struct nameserver *) mm_malloc(sizeof(struct nameserver));
if (!ns) return -1;
memset(ns, 0, sizeof(struct nameserver));
out2:
CLOSE_SOCKET(ns->socket);
out1:
- event_free(ns);
+ mm_free(ns);
log(EVDNS_LOG_WARN, "Unable to add nameserver %s: error %d", debug_ntoa(address), err);
return err;
}
const u16 trans_id = issuing_now ? transaction_id_pick(base) : 0xffff;
/* the request data is alloced in a single block with the header */
struct request *const req =
- (struct request *) event_malloc(sizeof(struct request) + request_max_len);
+ (struct request *) mm_malloc(sizeof(struct request) + request_max_len);
int rlen;
(void) flags;
return req;
err1:
- event_free(req);
+ mm_free(req);
return NULL;
}
if (req->ns) {
/* if it has a nameserver assigned then this is going */
/* straight into the inflight queue */
- evdns_request_insert(req, &base->req_head);
+ evdns_request_insert(req, &REQ_HEAD(base, req->trans_id));
base->global_requests_inflight++;
evdns_request_transmit(req);
} else {
struct search_domain *next, *dom;
for (dom = state->head; dom; dom = next) {
next = dom->next;
- event_free(dom);
+ mm_free(dom);
}
- event_free(state);
+ mm_free(state);
}
}
static struct search_state *
search_state_new(void) {
- struct search_state *state = (struct search_state *) event_malloc(sizeof(struct search_state));
+ struct search_state *state = (struct search_state *) mm_malloc(sizeof(struct search_state));
if (!state) return NULL;
memset(state, 0, sizeof(struct search_state));
state->refcount = 1;
if (!base->global_search_state) return;
base->global_search_state->num_domains++;
- sdomain = (struct search_domain *) event_malloc(sizeof(struct search_domain) + domain_len);
+ sdomain = (struct search_domain *) mm_malloc(sizeof(struct search_domain) + domain_len);
if (!sdomain) return;
memcpy( ((u8 *) sdomain) + sizeof(struct search_domain), domain, domain_len);
sdomain->next = base->global_search_state->head;
/* 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 *) event_malloc(base_len + need_to_append_dot + postfix_len + 1);
+ char *const newname = (char *) mm_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] = '.';
char *const new_name = search_make_new(base->global_search_state, 0, name);
if (!new_name) return 1;
req = request_new(base, type, new_name, flags, user_callback, user_arg);
- event_free(new_name);
+ mm_free(new_name);
if (!req) return 1;
req->search_index = 0;
}
- req->search_origname = event_strdup(name);
+ req->search_origname = mm_strdup(name);
req->search_state = base->global_search_state;
req->search_flags = flags;
base->global_search_state->refcount++;
if (!new_name) return 1;
log(EVDNS_LOG_DEBUG, "Search: now trying %s (%d)", new_name, req->search_index);
newreq = request_new(base, req->request_type, new_name, req->search_flags, req->user_callback, req->user_pointer);
- event_free(new_name);
+ mm_free(new_name);
if (!newreq) return 1;
newreq->search_origname = req->search_origname;
req->search_origname = NULL;
req->search_state = NULL;
}
if (req->search_origname) {
- event_free(req->search_origname);
+ mm_free(req->search_origname);
req->search_origname = NULL;
}
}
return r;
}
+static int
+evdns_base_set_max_requests_inflight(struct evdns_base *base, int maxinflight)
+{
+ int old_n_heads = base->n_req_heads, n_heads;
+ struct request **old_heads = base->req_heads, **new_heads, *req;
+ int i;
+ if (maxinflight < 1)
+ maxinflight = 1;
+ n_heads = (maxinflight+4) / 5;
+ assert(n_heads > 0);
+ new_heads = mm_malloc(n_heads * sizeof(struct request*));
+ if (!new_heads)
+ return (-1);
+ for (i=0; i < n_heads; ++i)
+ new_heads[i] = NULL;
+ if (old_heads) {
+ for (i = 0; i < old_n_heads; ++i) {
+ while (old_heads[i]) {
+ req = old_heads[i];
+ if (req->next == req) {
+ old_heads[i] = NULL;
+ } else {
+ old_heads[i] = req->next;
+ req->next->prev = req->prev;
+ req->prev->next = req->next;
+ }
+ evdns_request_insert(req, &new_heads[req->trans_id % n_heads]);
+ }
+ }
+ mm_free(old_heads);
+ }
+ base->req_heads = new_heads;
+ base->n_req_heads = n_heads;
+ base->global_max_requests_inflight = maxinflight;
+ return (0);
+}
+
/* exported function */
int
evdns_base_set_option(struct evdns_base *base,
if (!(flags & DNS_OPTION_MISC)) return 0;
log(EVDNS_LOG_DEBUG, "Setting maximum inflight requests to %d",
maxinflight);
- base->global_max_requests_inflight = maxinflight;
+ evdns_base_set_max_requests_inflight(base, maxinflight);
} else if (!strncmp(option, "attempts:", 9)) {
int retries = strtoint(val);
if (retries == -1) return -1;
}
if (st.st_size > 65535) { err = 3; goto out1; } /* no resolv.conf should be any bigger */
- resolv = (u8 *) event_malloc((size_t)st.st_size + 1);
+ resolv = (u8 *) mm_malloc((size_t)st.st_size + 1);
if (!resolv) { err = 4; goto out1; }
n = 0;
}
out2:
- event_free(resolv);
+ mm_free(resolv);
out1:
close(fd);
return err;
addr = ips;
while (ISDIGIT(*ips) || *ips == '.' || *ips == ':')
++ips;
- buf = event_malloc(ips-addr+1);
+ buf = mm_malloc(ips-addr+1);
if (!buf) return 4;
memcpy(buf, addr, ips-addr);
buf[ips-addr] = '\0';
r = evdns_nameserver_ip_add(buf);
- event_free(buf);
+ mm_free(buf);
if (r) return r;
}
return 0;
goto done;
}
- buf = event_malloc(size);
+ buf = mm_malloc(size);
if (!buf) { status = 4; goto done; }
fixed = buf;
r = fn(fixed, &size);
goto done;
}
if (r != ERROR_SUCCESS) {
- event_free(buf);
- buf = event_malloc(size);
+ mm_free(buf);
+ buf = mm_malloc(size);
if (!buf) { status = 4; goto done; }
fixed = buf;
r = fn(fixed, &size);
done:
if (buf)
- event_free(buf);
+ mm_free(buf);
if (handle)
FreeLibrary(handle);
return status;
if (RegQueryValueEx(key, subkey, 0, &type, NULL, &bufsz)
!= ERROR_MORE_DATA)
return -1;
- if (!(buf = event_malloc(bufsz)))
+ if (!(buf = mm_malloc(bufsz)))
return -1;
if (RegQueryValueEx(key, subkey, 0, &type, (LPBYTE)buf, &bufsz)
status = evdns_nameserver_ip_add_line(base,buf);
}
- event_free(buf);
+ mm_free(buf);
return status;
}
evdns_base_new(struct event_base *event_base, int initialize_nameservers)
{
struct evdns_base *base;
- base = event_malloc(sizeof(struct evdns_base));
+ base = mm_malloc(sizeof(struct evdns_base));
if (base == NULL)
return (NULL);
memset(base, 0, sizeof(struct evdns_base));
- base->req_head = base->req_waiting_head = NULL;
+ base->req_waiting_head = NULL;
+
+ /* Set max requests inflight and allocate req_heads. */
+ base->req_heads = NULL;
+ evdns_base_set_max_requests_inflight(base, 64);
+
base->server_head = NULL;
base->event_base = event_base;
base->global_good_nameservers = base->global_requests_inflight =
base->global_requests_waiting = 0;
- base->global_max_requests_inflight = 64;
+
base->global_timeout.tv_sec = 5;
base->global_timeout.tv_usec = 0;
base->global_max_reissues = 1;
{
struct nameserver *server, *server_next;
struct search_domain *dom, *dom_next;
+ int i;
- while (base->req_head) {
- if (fail_requests)
- reply_callback(base->req_head, 0, DNS_ERR_SHUTDOWN, NULL);
- request_finished(base->req_head, &base->req_head);
+ for (i = 0; i < base->n_req_heads; ++i) {
+ while (base->req_heads[i]) {
+ if (fail_requests)
+ reply_callback(base->req_heads[i], 0, DNS_ERR_SHUTDOWN, NULL);
+ request_finished(base->req_heads[i], &REQ_HEAD(base, base->req_heads[i]->trans_id));
+ }
}
while (base->req_waiting_head) {
if (fail_requests)
(void) event_del(&server->event);
if (server->state == 0)
(void) event_del(&server->timeout_event);
- event_free(server);
+ mm_free(server);
if (server_next == base->server_head)
break;
}
if (base->global_search_state) {
for (dom = base->global_search_state->head; dom; dom = dom_next) {
dom_next = dom->next;
- event_free(dom);
+ mm_free(dom);
}
- event_free(base->global_search_state);
+ mm_free(base->global_search_state);
base->global_search_state = NULL;
}
- event_free(base);
+ mm_free(base);
}
void
int i;
struct event_base *base;
- if ((base = event_calloc(1, sizeof(struct event_base))) == NULL)
+ if ((base = mm_calloc(1, sizeof(struct event_base))) == NULL)
event_err(1, "%s: calloc", __func__);
event_sigcb = NULL;
min_heap_dtor(&base->timeheap);
for (i = 0; i < base->nactivequeues; ++i)
- event_free(base->activequeues[i]);
- event_free(base->activequeues);
+ mm_free(base->activequeues[i]);
+ mm_free(base->activequeues);
assert(TAILQ_EMPTY(&base->eventqueue));
- event_free(base);
+ mm_free(base);
}
/* reinitialized the event base after a fork */
if (base->nactivequeues && npriorities != base->nactivequeues) {
for (i = 0; i < base->nactivequeues; ++i) {
- event_free(base->activequeues[i]);
+ mm_free(base->activequeues[i]);
}
- event_free(base->activequeues);
+ mm_free(base->activequeues);
}
/* Allocate our priority queues */
base->nactivequeues = npriorities;
- base->activequeues = (struct event_list **)event_calloc(
+ base->activequeues = (struct event_list **)mm_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] = event_malloc(sizeof(struct event_list));
+ base->activequeues[i] = mm_malloc(sizeof(struct event_list));
if (base->activequeues[i] == NULL)
event_err(1, "%s: malloc", __func__);
TAILQ_INIT(base->activequeues[i]);
struct event_once *eonce = arg;
(*eonce->cb)(fd, events, eonce->arg);
- event_free(eonce);
+ mm_free(eonce);
}
/* not threadsafe, event scheduled once. */
if (events & EV_SIGNAL)
return (-1);
- if ((eonce = event_calloc(1, sizeof(struct event_once))) == NULL)
+ if ((eonce = mm_calloc(1, sizeof(struct event_once))) == NULL)
return (-1);
eonce->cb = callback;
event_set(&eonce->ev, fd, events, event_once_cb, eonce);
} else {
/* Bad event combination */
- event_free(eonce);
+ mm_free(eonce);
return (-1);
}
if (res == 0)
res = event_add(&eonce->ev, tv);
if (res != 0) {
- event_free(eonce);
+ mm_free(eonce);
return (res);
}
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;
+static void *(*_mm_malloc_fn)(size_t sz) = NULL;
+static void *(*_mm_realloc_fn)(void *p, size_t sz) = NULL;
+static void (*_mm_free_fn)(void *p) = NULL;
void *
-event_malloc(size_t sz)
+mm_malloc(size_t sz)
{
- if (_event_malloc_fn)
- return _event_malloc_fn(sz);
+ if (_mm_malloc_fn)
+ return _mm_malloc_fn(sz);
else
return malloc(sz);
}
void *
-event_calloc(size_t count, size_t size)
+mm_calloc(size_t count, size_t size)
{
- if (_event_malloc_fn) {
+ if (_mm_malloc_fn) {
size_t sz = count * size;
- void *p = _event_malloc_fn(sz);
+ void *p = _mm_malloc_fn(sz);
if (p)
memset(p, 0, sz);
return p;
}
char *
-event_strdup(const char *str)
+mm_strdup(const char *str)
{
- if (_event_malloc_fn) {
+ if (_mm_malloc_fn) {
size_t ln = strlen(str);
- void *p = _event_malloc_fn(ln+1);
+ void *p = _mm_malloc_fn(ln+1);
if (p)
memcpy(p, str, ln+1);
return p;
}
void *
-event_realloc(void *ptr, size_t sz)
+mm_realloc(void *ptr, size_t sz)
{
- if (_event_realloc_fn)
- return _event_realloc_fn(ptr, sz);
+ if (_mm_realloc_fn)
+ return _mm_realloc_fn(ptr, sz);
else
return realloc(ptr, sz);
}
void
-event_free(void *ptr)
+mm_free(void *ptr)
{
- if (_event_realloc_fn)
- _event_free_fn(ptr);
+ if (_mm_realloc_fn)
+ _mm_free_fn(ptr);
else
free(ptr);
}
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;
+ _mm_malloc_fn = malloc_fn;
+ _mm_realloc_fn = realloc_fn;
+ _mm_free_fn = free_fn;
}
/* support for threading */
tag != need_tag)
return (-1);
- *pstring = event_malloc(tag_len + 1);
+ *pstring = mm_malloc(tag_len + 1);
if (*pstring == NULL)
event_err(1, "%s: malloc", __func__);
evbuffer_remove(evbuf, *pstring, tag_len);
if (getenv("EVENT_NOEVPORT"))
return (NULL);
- if (!(evpd = event_calloc(1, sizeof(struct evport_data))))
+ if (!(evpd = mm_calloc(1, sizeof(struct evport_data))))
return (NULL);
if ((evpd->ed_port = port_create()) == -1) {
- event_free(evpd);
+ mm_free(evpd);
return (NULL);
}
/*
* Initialize file descriptor structure
*/
- evpd->ed_fds = event_calloc(DEFAULT_NFDS, sizeof(struct fd_info));
+ evpd->ed_fds = mm_calloc(DEFAULT_NFDS, sizeof(struct fd_info));
if (evpd->ed_fds == NULL) {
close(evpd->ed_port);
- event_free(evpd);
+ mm_free(evpd);
return (NULL);
}
evpd->ed_nevents = DEFAULT_NFDS;
check_evportop(epdp);
- tmp = event_realloc(epdp->ed_fds, sizeof(struct fd_info) * newsize);
+ tmp = mm_realloc(epdp->ed_fds, sizeof(struct fd_info) * newsize);
if (NULL == tmp)
return -1;
epdp->ed_fds = tmp;
close(evpd->ed_port);
if (evpd->ed_fds)
- event_free(evpd->ed_fds);
- event_free(evpd);
+ mm_free(evpd->ed_fds);
+ mm_free(evpd);
}
struct evrpc_base *
evrpc_init(struct evhttp *http_server)
{
- struct evrpc_base* base = event_calloc(1, sizeof(struct evrpc_base));
+ struct evrpc_base* base = mm_calloc(1, sizeof(struct evrpc_base));
if (base == NULL)
return (NULL);
while ((hook = TAILQ_FIRST(&base->output_hooks)) != NULL) {
assert(evrpc_remove_hook(base, OUTPUT, hook));
}
- event_free(base);
+ mm_free(base);
}
void *
assert(hook_type == INPUT || hook_type == OUTPUT);
}
- hook = event_calloc(1, sizeof(struct evrpc_hook));
+ hook = mm_calloc(1, sizeof(struct evrpc_hook));
assert(hook != NULL);
hook->process = cb;
TAILQ_FOREACH(hook, head, next) {
if (hook == handle) {
TAILQ_REMOVE(head, hook, next);
- event_free(hook);
+ mm_free(hook);
return (1);
}
}
int constructed_uri_len;
constructed_uri_len = strlen(EVRPC_URI_PREFIX) + strlen(uri) + 1;
- if ((constructed_uri = event_malloc(constructed_uri_len)) == NULL)
+ if ((constructed_uri = mm_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));
evrpc_request_cb,
rpc);
- event_free(constructed_uri);
+ mm_free(constructed_uri);
return (0);
}
}
TAILQ_REMOVE(&base->registered_rpcs, rpc, next);
- event_free((char *)rpc->uri);
- event_free(rpc);
+ mm_free((char *)rpc->uri);
+ mm_free(rpc);
registered_uri = evrpc_construct_uri(name);
/* remove the http server callback */
assert(evhttp_del_cb(base->http_server, registered_uri) == 0);
- event_free(registered_uri);
+ mm_free(registered_uri);
return (0);
}
EVBUFFER_LENGTH(req->input_buffer) <= 0)
goto error;
- rpc_state = event_calloc(1, sizeof(struct evrpc_req_generic));
+ rpc_state = mm_calloc(1, sizeof(struct evrpc_req_generic));
if (rpc_state == NULL)
goto error;
rpc_state->rpc = rpc;
rpc->reply_free(rpc_state->reply);
if (rpc_state->rpc_data != NULL)
evbuffer_free(rpc_state->rpc_data);
- event_free(rpc_state);
+ mm_free(rpc_state);
}
static void
struct evrpc_pool *
evrpc_pool_new(struct event_base *base)
{
- struct evrpc_pool *pool = event_calloc(1, sizeof(struct evrpc_pool));
+ struct evrpc_pool *pool = mm_calloc(1, sizeof(struct evrpc_pool));
if (pool == NULL)
return (NULL);
{
if (request->hook_meta != NULL)
evrpc_hook_context_free(request->hook_meta);
- event_free(request->name);
- event_free(request);
+ mm_free(request->name);
+ mm_free(request);
}
void
while ((pause = TAILQ_FIRST(&pool->paused_requests)) != NULL) {
TAILQ_REMOVE(&pool->paused_requests, pause, next);
- event_free(pause);
+ mm_free(pause);
}
while ((connection = TAILQ_FIRST(&pool->connections)) != NULL) {
assert(evrpc_remove_hook(pool, OUTPUT, hook));
}
- event_free(pool);
+ mm_free(pool);
}
/*
/* start the request over the connection */
res = evhttp_make_request(connection, req, EVHTTP_REQ_POST, uri);
- event_free(uri);
+ mm_free(uri);
if (res == -1)
goto error;
void (*cb)(void *, enum EVRPC_HOOK_RESULT))
{
struct _evrpc_hooks *base = vbase;
- struct evrpc_hook_ctx *pause = event_malloc(sizeof(*pause));
+ struct evrpc_hook_ctx *pause = mm_malloc(sizeof(*pause));
if (pause == NULL)
return (-1);
void *cbarg)
{
struct evrpc_request_wrapper *ctx = (struct evrpc_request_wrapper *)
- event_malloc(sizeof(struct evrpc_request_wrapper));
+ mm_malloc(sizeof(struct evrpc_request_wrapper));
if (ctx == NULL)
return (NULL);
ctx->pool = pool;
ctx->hook_meta = NULL;
ctx->evcon = NULL;
- ctx->name = event_strdup(rpcname);
+ ctx->name = mm_strdup(rpcname);
if (ctx->name == NULL) {
- event_free(ctx);
+ mm_free(ctx);
return (NULL);
}
ctx->cb = cb;
while ((entry = TAILQ_FIRST(meta_data)) != NULL) {
TAILQ_REMOVE(meta_data, entry, next);
- event_free(entry->key);
- event_free(entry->data);
- event_free(entry);
+ mm_free(entry->key);
+ mm_free(entry->data);
+ mm_free(entry);
}
}
evrpc_hook_meta_new(void)
{
struct evrpc_hook_meta *ctx;
- ctx = event_malloc(sizeof(struct evrpc_hook_meta));
+ ctx = mm_malloc(sizeof(struct evrpc_hook_meta));
assert(ctx != NULL);
TAILQ_INIT(&ctx->meta_data);
evrpc_hook_context_free(struct evrpc_hook_meta *ctx)
{
evrpc_meta_data_free(&ctx->meta_data);
- event_free(ctx);
+ mm_free(ctx);
}
/* Adds meta data */
if ((store = req->hook_meta) == NULL)
store = req->hook_meta = evrpc_hook_meta_new();
- assert((meta = event_malloc(sizeof(struct evrpc_meta))) != NULL);
- assert((meta->key = event_strdup(key)) != NULL);
+ assert((meta = mm_malloc(sizeof(struct evrpc_meta))) != NULL);
+ assert((meta->key = mm_strdup(key)) != NULL);
meta->data_size = data_size;
- assert((meta->data = event_malloc(data_size)) != NULL);
+ assert((meta->data = mm_malloc(data_size)) != NULL);
memcpy(meta->data, data, data_size);
TAILQ_INSERT_TAIL(&store->meta_data, meta, next);
ai->ai_socktype = SOCK_STREAM;
ai->ai_protocol = 0;
ai->ai_addrlen = sizeof(struct sockaddr_in);
- if (NULL == (ai->ai_addr = event_malloc(ai->ai_addrlen)))
+ if (NULL == (ai->ai_addr = mm_malloc(ai->ai_addrlen)))
return (-1);
sa = (struct sockaddr_in*)ai->ai_addr;
memset(sa, 0, ai->ai_addrlen);
static void
fake_freeaddrinfo(struct addrinfo *ai)
{
- event_free(ai->ai_addr);
+ mm_free(ai->ai_addr);
}
#endif
for (i = 0; i < old_size; ++i)
new_size += strlen(html_replace(html[i], scratch_space));
- p = escaped_html = event_malloc(new_size + 1);
+ p = escaped_html = mm_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) {
default: /* xxx: probably should just error on default */
/* the callback looks at the uri to determine errors */
if (req->uri) {
- event_free(req->uri);
+ mm_free(req->uri);
req->uri = NULL;
}
break;
/* the last chunk is on a new line? */
if (strlen(p) == 0) {
- event_free(p);
+ mm_free(p);
continue;
}
req->ntoread = evutil_strtoll(p, &endp, 16);
error = *p == '\0' || (*endp != '\0' && *endp != ' ');
- event_free(p);
+ mm_free(p);
if (error) {
/* could not get chunk size */
return (-1);
EVUTIL_CLOSESOCKET(evcon->fd);
if (evcon->bind_address != NULL)
- event_free(evcon->bind_address);
+ mm_free(evcon->bind_address);
if (evcon->address != NULL)
- event_free(evcon->address);
+ mm_free(evcon->address);
if (evcon->input_buffer != NULL)
evbuffer_free(evcon->input_buffer);
if (evcon->output_buffer != NULL)
evbuffer_free(evcon->output_buffer);
- event_free(evcon);
+ mm_free(evcon);
}
void
{
assert(evcon->state == EVCON_DISCONNECTED);
if (evcon->bind_address)
- event_free(evcon->bind_address);
- if ((evcon->bind_address = event_strdup(address)) == NULL)
+ mm_free(evcon->bind_address);
+ if ((evcon->bind_address = mm_strdup(address)) == NULL)
event_err(1, "%s: strdup", __func__);
}
return (-1);
}
- if ((req->response_code_line = event_strdup(readable)) == NULL)
+ if ((req->response_code_line = mm_strdup(readable)) == NULL)
event_err(1, "%s: strdup", __func__);
return (0);
return (-1);
}
- if ((req->uri = event_strdup(uri)) == NULL) {
+ if ((req->uri = mm_strdup(uri)) == NULL) {
event_debug(("%s: evhttp_decode_uri", __func__));
return (-1);
}
header != NULL;
header = TAILQ_FIRST(headers)) {
TAILQ_REMOVE(headers, header, next);
- event_free(header->key);
- event_free(header->value);
- event_free(header);
+ mm_free(header->key);
+ mm_free(header->value);
+ mm_free(header);
}
}
/* Free and remove the header that we found */
TAILQ_REMOVE(headers, header, next);
- event_free(header->key);
- event_free(header->value);
- event_free(header);
+ mm_free(header->key);
+ mm_free(header->value);
+ mm_free(header);
return (0);
}
return (-1);
}
- header = event_calloc(1, sizeof(struct evkeyval));
+ header = mm_calloc(1, sizeof(struct evkeyval));
if (header == NULL) {
event_warn("%s: calloc", __func__);
return (-1);
}
- if ((header->key = event_strdup(key)) == NULL) {
- event_free(header);
+ if ((header->key = mm_strdup(key)) == NULL) {
+ mm_free(header);
event_warn("%s: strdup", __func__);
return (-1);
}
- if ((header->value = event_strdup(value)) == NULL) {
- event_free(header->key);
- event_free(header);
+ if ((header->value = mm_strdup(value)) == NULL) {
+ mm_free(header->key);
+ mm_free(header);
event_warn("%s: strdup", __func__);
return (-1);
}
if (*line == '\0') { /* Last header - Done */
done = 1;
- event_free(line);
+ mm_free(line);
break;
}
goto error;
}
- event_free(line);
+ mm_free(line);
}
return (done);
error:
- event_free(line);
+ mm_free(line);
return (-1);
}
event_debug(("Attempting connection to %s:%d\n", address, port));
- if ((evcon = event_calloc(1, sizeof(struct evhttp_connection))) == NULL) {
+ if ((evcon = mm_calloc(1, sizeof(struct evhttp_connection))) == NULL) {
event_warn("%s: calloc failed", __func__);
goto error;
}
evcon->timeout = -1;
evcon->retry_cnt = evcon->retry_max = 0;
- if ((evcon->address = event_strdup(address)) == NULL) {
+ if ((evcon->address = mm_strdup(address)) == NULL) {
event_warn("%s: strdup failed", __func__);
goto error;
}
req->kind = EVHTTP_REQUEST;
req->type = type;
if (req->uri != NULL)
- event_free(req->uri);
- if ((req->uri = event_strdup(uri)) == NULL)
+ mm_free(req->uri);
+ if ((req->uri = mm_strdup(uri)) == NULL)
event_err(1, "%s: strdup", __func__);
/* Set the protocol version if it is not supplied */
req->kind = EVHTTP_RESPONSE;
req->response_code = code;
if (req->response_code_line != NULL)
- event_free(req->response_code_line);
- req->response_code_line = event_strdup(reason);
+ mm_free(req->response_code_line);
+ req->response_code_line = mm_strdup(reason);
}
void
}
}
evbuffer_add(buf, "", 1);
- p = event_strdup((char *)EVBUFFER_DATA(buf));
+ p = mm_strdup((char *)EVBUFFER_DATA(buf));
evbuffer_free(buf);
return (p);
char c, *ret;
int i, j, in_query = 0;
- ret = event_malloc(strlen(uri) + 1);
+ ret = mm_malloc(strlen(uri) + 1);
if (ret == NULL)
event_err(1, "%s: malloc(%lu)", __func__,
(unsigned long)(strlen(uri) + 1));
if (strchr(uri, '?') == NULL)
return;
- if ((line = event_strdup(uri)) == NULL)
+ if ((line = mm_strdup(uri)) == NULL)
event_err(1, "%s: strdup", __func__);
value = evhttp_decode_uri(value);
event_debug(("Query Param: %s -> %s\n", key, value));
evhttp_add_header(headers, key, value);
- event_free(value);
+ mm_free(value);
}
error:
- event_free(line);
+ mm_free(line);
}
static struct evhttp_cb *
evbuffer_add_printf(buf, ERR_FORMAT, escaped_html);
- event_free(escaped_html);
+ mm_free(escaped_html);
evhttp_send_page(req, buf);
{
struct evhttp *http = NULL;
- if ((http = event_calloc(1, sizeof(struct evhttp))) == NULL) {
+ if ((http = mm_calloc(1, sizeof(struct evhttp))) == NULL) {
event_warn("%s: calloc", __func__);
return (NULL);
}
struct evhttp *http = evhttp_new_object();
if (evhttp_bind_socket(http, address, port) == -1) {
- event_free(http);
+ mm_free(http);
return (NULL);
}
while ((http_cb = TAILQ_FIRST(&http->callbacks)) != NULL) {
TAILQ_REMOVE(&http->callbacks, http_cb, next);
- event_free(http_cb->what);
- event_free(http_cb);
+ mm_free(http_cb->what);
+ mm_free(http_cb);
}
- event_free(http);
+ mm_free(http);
}
void
{
struct evhttp_cb *http_cb;
- if ((http_cb = event_calloc(1, sizeof(struct evhttp_cb))) == NULL)
+ if ((http_cb = mm_calloc(1, sizeof(struct evhttp_cb))) == NULL)
event_err(1, "%s: calloc", __func__);
- http_cb->what = event_strdup(uri);
+ http_cb->what = mm_strdup(uri);
http_cb->cb = cb;
http_cb->cbarg = cbarg;
return (-1);
TAILQ_REMOVE(&http->callbacks, http_cb, next);
- event_free(http_cb->what);
- event_free(http_cb);
+ mm_free(http_cb->what);
+ mm_free(http_cb);
return (0);
}
struct evhttp_request *req = NULL;
/* Allocate request structure */
- if ((req = event_calloc(1, sizeof(struct evhttp_request))) == NULL) {
+ if ((req = mm_calloc(1, sizeof(struct evhttp_request))) == NULL) {
event_warn("%s: calloc", __func__);
goto error;
}
req->kind = EVHTTP_RESPONSE;
- req->input_headers = event_calloc(1, sizeof(struct evkeyvalq));
+ req->input_headers = mm_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 = event_calloc(1, sizeof(struct evkeyvalq));
+ req->output_headers = mm_calloc(1, sizeof(struct evkeyvalq));
if (req->output_headers == NULL) {
event_warn("%s: calloc", __func__);
goto error;
evhttp_request_free(struct evhttp_request *req)
{
if (req->remote_host != NULL)
- event_free(req->remote_host);
+ mm_free(req->remote_host);
if (req->uri != NULL)
- event_free(req->uri);
+ mm_free(req->uri);
if (req->response_code_line != NULL)
- event_free(req->response_code_line);
+ mm_free(req->response_code_line);
evhttp_clear_headers(req->input_headers);
- event_free(req->input_headers);
+ mm_free(req->input_headers);
evhttp_clear_headers(req->output_headers);
- event_free(req->output_headers);
+ mm_free(req->output_headers);
if (req->input_buffer != NULL)
evbuffer_free(req->input_buffer);
if (req->output_buffer != NULL)
evbuffer_free(req->output_buffer);
- event_free(req);
+ mm_free(req);
}
void
name_from_addr(sa, salen, &hostname, &portname);
if (hostname==NULL || portname==NULL) {
- if (hostname) event_free(hostname);
- if (portname) event_free(portname);
+ if (hostname) mm_free(hostname);
+ if (portname) mm_free(portname);
return (NULL);
}
/* we need a connection object to put the http request on */
evcon = evhttp_connection_new(hostname, atoi(portname));
- event_free(hostname);
- event_free(portname);
+ mm_free(hostname);
+ mm_free(portname);
if (evcon == NULL)
return (NULL);
req->kind = EVHTTP_REQUEST;
- if ((req->remote_host = event_strdup(evcon->address)) == NULL)
+ if ((req->remote_host = mm_strdup(evcon->address)) == NULL)
event_err(1, "%s: strdup", __func__);
req->remote_port = evcon->port;
return;
}
- *phost = event_strdup(ntop);
- *pport = event_strdup(strport);
+ *phost = mm_strdup(ntop);
+ *pport = mm_strdup(strport);
#else
/* XXXX */
#endif
if (getenv("EVENT_NOKQUEUE"))
return (NULL);
- if (!(kqueueop = event_calloc(1, sizeof(struct kqop))))
+ if (!(kqueueop = mm_calloc(1, sizeof(struct kqop))))
return (NULL);
/* Initalize the kernel queue */
if ((kq = kqueue()) == -1) {
event_warn("kqueue");
- event_free (kqueueop);
+ mm_free (kqueueop);
return (NULL);
}
kqueueop->pid = getpid();
/* Initalize fields */
- kqueueop->changes = event_malloc(NEVENT * sizeof(struct kevent));
+ kqueueop->changes = mm_malloc(NEVENT * sizeof(struct kevent));
if (kqueueop->changes == NULL) {
- event_free (kqueueop);
+ mm_free (kqueueop);
return (NULL);
}
- kqueueop->events = event_malloc(NEVENT * sizeof(struct kevent));
+ kqueueop->events = mm_malloc(NEVENT * sizeof(struct kevent));
if (kqueueop->events == NULL) {
- event_free (kqueueop->changes);
- event_free (kqueueop);
+ mm_free (kqueueop->changes);
+ mm_free (kqueueop);
return (NULL);
}
kqueueop->nevents = NEVENT;
kqueueop->events[0].ident != -1 ||
kqueueop->events[0].flags != EV_ERROR) {
event_warn("%s: detected broken kqueue; not using.", __func__);
- event_free(kqueueop->changes);
- event_free(kqueueop->events);
- event_free(kqueueop);
+ mm_free(kqueueop->changes);
+ mm_free(kqueueop->events);
+ mm_free(kqueueop);
close(kq);
return (NULL);
}
nevents *= 2;
- newchange = event_realloc(kqop->changes,
+ newchange = mm_realloc(kqop->changes,
nevents * sizeof(struct kevent));
if (newchange == NULL) {
event_warn("%s: malloc", __func__);
}
kqop->changes = newchange;
- newresult = event_realloc(kqop->events,
+ newresult = mm_realloc(kqop->events,
nevents * sizeof(struct kevent));
/*
struct kqop *kqop = arg;
if (kqop->changes)
- event_free(kqop->changes);
+ mm_free(kqop->changes);
if (kqop->events)
- event_free(kqop->events);
+ mm_free(kqop->events);
if (kqop->kq >= 0 && kqop->pid == getpid())
close(kqop->kq);
memset(kqop, 0, sizeof(struct kqop));
- event_free(kqop);
+ mm_free(kqop);
}
#endif
/* Internal use only: Memory allocation functions. */
-void *event_malloc(size_t sz);
-void *event_calloc(size_t count, size_t size);
-char *event_strdup(const char *s);
-void *event_realloc(void *p, size_t sz);
-void event_free(void *p);
+void *mm_malloc(size_t sz);
+void *mm_calloc(size_t count, size_t size);
+char *mm_strdup(const char *s);
+void *mm_realloc(void *p, size_t sz);
+void mm_free(void *p);
#ifdef __cplusplus
}
if (getenv("EVENT_NOPOLL"))
return (NULL);
- if (!(pollop = event_calloc(1, sizeof(struct pollop))))
+ if (!(pollop = mm_calloc(1, sizeof(struct pollop))))
return (NULL);
evsignal_init(base);
tmp_event_count = pop->event_count * 2;
/* We need more file descriptors */
- tmp_event_set = event_realloc(pop->event_set,
+ tmp_event_set = mm_realloc(pop->event_set,
tmp_event_count * sizeof(struct pollfd));
if (tmp_event_set == NULL) {
event_warn("realloc");
}
pop->event_set = tmp_event_set;
- tmp_event_r_back = event_realloc(pop->event_r_back,
+ tmp_event_r_back = mm_realloc(pop->event_r_back,
tmp_event_count * sizeof(struct event *));
if (tmp_event_r_back == NULL) {
/* event_set overallocated; that's okay. */
}
pop->event_r_back = tmp_event_r_back;
- tmp_event_w_back = event_realloc(pop->event_w_back,
+ tmp_event_w_back = mm_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
while (new_count <= ev->ev_fd)
new_count *= 2;
tmp_idxplus1_by_fd =
- event_realloc(pop->idxplus1_by_fd, new_count * sizeof(int));
+ mm_realloc(pop->idxplus1_by_fd, new_count * sizeof(int));
if (tmp_idxplus1_by_fd == NULL) {
event_warn("realloc");
return (-1);
evsignal_dealloc(base);
if (pop->event_set)
- event_free(pop->event_set);
+ mm_free(pop->event_set);
if (pop->event_r_back)
- event_free(pop->event_r_back);
+ mm_free(pop->event_r_back);
if (pop->event_w_back)
- event_free(pop->event_w_back);
+ mm_free(pop->event_w_back);
if (pop->idxplus1_by_fd)
- event_free(pop->idxplus1_by_fd);
+ mm_free(pop->idxplus1_by_fd);
memset(pop, 0, sizeof(struct pollop));
- event_free(pop);
+ mm_free(pop);
}
if (getenv("EVENT_NOSELECT"))
return (NULL);
- if (!(sop = event_calloc(1, sizeof(struct selectop))))
+ if (!(sop = mm_calloc(1, sizeof(struct selectop))))
return (NULL);
select_resize(sop, howmany(32 + 1, NFDBITS)*sizeof(fd_mask));
if (sop->event_readset_in)
check_selectop(sop);
- if ((readset_in = event_realloc(sop->event_readset_in, fdsz)) == NULL)
+ if ((readset_in = mm_realloc(sop->event_readset_in, fdsz)) == NULL)
goto error;
sop->event_readset_in = readset_in;
- if ((readset_out = event_realloc(sop->event_readset_out, fdsz)) == NULL)
+ if ((readset_out = mm_realloc(sop->event_readset_out, fdsz)) == NULL)
goto error;
sop->event_readset_out = readset_out;
- if ((writeset_in = event_realloc(sop->event_writeset_in, fdsz)) == NULL)
+ if ((writeset_in = mm_realloc(sop->event_writeset_in, fdsz)) == NULL)
goto error;
sop->event_writeset_in = writeset_in;
- if ((writeset_out = event_realloc(sop->event_writeset_out, fdsz)) == NULL)
+ if ((writeset_out = mm_realloc(sop->event_writeset_out, fdsz)) == NULL)
goto error;
sop->event_writeset_out = writeset_out;
- if ((r_by_fd = event_realloc(sop->event_r_by_fd,
+ if ((r_by_fd = mm_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 = event_realloc(sop->event_w_by_fd,
+ if ((w_by_fd = mm_realloc(sop->event_w_by_fd,
n_events * sizeof(struct event*))) == NULL)
goto error;
sop->event_w_by_fd = w_by_fd;
evsignal_dealloc(base);
if (sop->event_readset_in)
- event_free(sop->event_readset_in);
+ mm_free(sop->event_readset_in);
if (sop->event_writeset_in)
- event_free(sop->event_writeset_in);
+ mm_free(sop->event_writeset_in);
if (sop->event_readset_out)
- event_free(sop->event_readset_out);
+ mm_free(sop->event_readset_out);
if (sop->event_writeset_out)
- event_free(sop->event_writeset_out);
+ mm_free(sop->event_writeset_out);
if (sop->event_r_by_fd)
- event_free(sop->event_r_by_fd);
+ mm_free(sop->event_r_by_fd);
if (sop->event_w_by_fd)
- event_free(sop->event_w_by_fd);
+ mm_free(sop->event_w_by_fd);
memset(sop, 0, sizeof(struct selectop));
- event_free(sop);
+ mm_free(sop);
}
event_debug(("%s: evsignal (%d) >= sh_old_max (%d), resizing",
__func__, evsignal, sig->sh_old_max));
sig->sh_old_max = evsignal + 1;
- p = event_realloc(sig->sh_old, sig->sh_old_max * sizeof *sig->sh_old);
+ p = mm_realloc(sig->sh_old, sig->sh_old_max * sizeof *sig->sh_old);
if (p == NULL) {
event_warn("realloc");
return (-1);
}
/* allocate space for previous handler out of dynamic array */
- sig->sh_old[evsignal] = event_malloc(sizeof *sig->sh_old[evsignal]);
+ sig->sh_old[evsignal] = mm_malloc(sizeof *sig->sh_old[evsignal]);
if (sig->sh_old[evsignal] == NULL) {
event_warn("malloc");
return (-1);
if (sigaction(evsignal, &sa, sig->sh_old[evsignal]) == -1) {
event_warn("sigaction");
- event_free(sig->sh_old[evsignal]);
+ mm_free(sig->sh_old[evsignal]);
return (-1);
}
#else
if ((sh = signal(evsignal, handler)) == SIG_ERR) {
event_warn("signal");
- event_free(sig->sh_old[evsignal]);
+ mm_free(sig->sh_old[evsignal]);
return (-1);
}
*sig->sh_old[evsignal] = sh;
}
#endif
- event_free(sh);
+ mm_free(sh);
return ret;
}
base->sig.sh_old_max = 0;
/* per index frees are handled in evsignal_del() */
- event_free(base->sig.sh_old);
+ mm_free(base->sig.sh_old);
}