Prefer calloc(a,b) to malloc(a*b). via openbsd.

svn:r1531
This commit is contained in:
Nick Mathewson 2009-11-15 19:00:12 +00:00
parent 629a613398
commit 18a8cfac39
4 changed files with 7 additions and 9 deletions

View File

@ -117,7 +117,7 @@ epoll_init(struct event_base *base)
epollop->epfd = epfd;
/* Initialize fields */
epollop->events = mm_malloc(INITIAL_NEVENT * sizeof(struct epoll_event));
epollop->events = mm_calloc(INITIAL_NEVENT, sizeof(struct epoll_event));
if (epollop->events == NULL) {
mm_free(epollop);
return (NULL);

View File

@ -1110,7 +1110,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 = mm_malloc(sizeof(struct evdns_server_question *) * questions);
server_req->base.questions = mm_calloc(sizeof(struct evdns_server_question *), questions);
if (server_req->base.questions == NULL)
goto err;
@ -3143,11 +3143,9 @@ evdns_base_set_max_requests_inflight(struct evdns_base *base, int maxinflight)
maxinflight = 1;
n_heads = (maxinflight+4) / 5;
EVUTIL_ASSERT(n_heads > 0);
new_heads = mm_malloc(n_heads * sizeof(struct evdns_request*));
new_heads = mm_calloc(n_heads, sizeof(struct evdns_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]) {

View File

@ -539,7 +539,7 @@ event_get_supported_methods(void)
}
/* allocate one more than we need for the NULL pointer */
tmp = mm_malloc((i + 1) * sizeof(char *));
tmp = mm_calloc((i + 1), sizeof(char *));
if (tmp == NULL)
return (NULL);

View File

@ -133,13 +133,13 @@ kq_init(struct event_base *base)
kqueueop->pid = getpid();
/* Initialize fields */
kqueueop->changes = mm_malloc(NEVENT * sizeof(struct kevent));
kqueueop->changes = mm_calloc(NEVENT, sizeof(struct kevent));
if (kqueueop->changes == NULL)
goto err;
kqueueop->pend_changes = mm_malloc(NEVENT * sizeof(struct kevent));
kqueueop->pend_changes = mm_calloc(NEVENT, sizeof(struct kevent));
if (kqueueop->pend_changes == NULL)
goto err;
kqueueop->events = mm_malloc(NEVENT * sizeof(struct kevent));
kqueueop->events = mm_calloc(NEVENT, sizeof(struct kevent));
if (kqueueop->events == NULL)
goto err;
kqueueop->events_size = kqueueop->changes_size =