goto fail;
}
- keys_ref->tlskeys = malloc(TLS_TICKETS_NO * sizeof(union tls_sess_key));
+ keys_ref->tlskeys = malloc(array_size_or_fail(TLS_TICKETS_NO, sizeof(union tls_sess_key)));
if (!keys_ref->tlskeys) {
memprintf(err, "'%s' : allocation error", args[cur_arg+1]);
goto fail;
global.cfg_curr_line = 0;
global.cfg_curr_file = file;
- if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) {
+ if ((thisline = malloc(array_size_or_fail(sizeof(*thisline), linesize))) == NULL) {
ha_alert("Out of memory trying to allocate a buffer for a configuration line.\n");
err_code = -1;
goto err;
char *newline;
int newlinesize = linesize * 2;
- newline = realloc(thisline, sizeof(*thisline) * newlinesize);
+ newline = realloc(thisline, array_size_or_fail(sizeof(*thisline), newlinesize));
if (newline == NULL) {
ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n",
file, linenum);
/* We will send sockets MAX_SEND_FD per MAX_SEND_FD, allocate a
* buffer big enough to store the socket information.
*/
- tmpbuf = malloc(MAX_SEND_FD * (1 + MAXPATHLEN + 1 + IFNAMSIZ + sizeof(int)));
+ tmpbuf = malloc(array_size_or_fail(MAX_SEND_FD, (1 + MAXPATHLEN + 1 + IFNAMSIZ + sizeof(int))));
if (tmpbuf == NULL) {
ha_warning("Failed to allocate memory to transfer socket information\n");
goto out;
{
/* Allocate the buffer if not already done. */
if (unlikely(b_is_null(&usermsgs_buf))) {
- usermsgs_buf.area = malloc(USER_MESSAGES_BUFSIZE * sizeof(char));
+ usermsgs_buf.area = malloc(array_size_or_fail(USER_MESSAGES_BUFSIZE, sizeof(char)));
if (usermsgs_buf.area)
usermsgs_buf.size = USER_MESSAGES_BUFSIZE;
}
struct poller *bp;
/* always provide an aligned fdtab */
- if ((fdtab = ha_aligned_zalloc(64, global.maxsock * sizeof(*fdtab))) == NULL) {
+ if ((fdtab = ha_aligned_zalloc(64, array_size_or_fail(global.maxsock, sizeof(*fdtab)))) == NULL) {
ha_alert("Not enough memory to allocate %d entries for fdtab!\n", global.maxsock);
goto fail_tab;
}
oldpids_sig = SIGTERM; /* terminate immediately */
while (argc > 1 && argv[1][0] != '-') {
char * endptr = NULL;
- oldpids = realloc(oldpids, (nb_oldpids + 1) * sizeof(int));
+ oldpids = realloc(oldpids, array_size_or_fail(nb_oldpids + 1, sizeof(int)));
if (!oldpids) {
ha_alert("Cannot allocate old pid : out of memory.\n");
exit(1);
goto error;
}
if (def->lb.smp_rgs) {
- cpy->lb.smp_rgs = malloc(sizeof(*cpy->lb.smp_rgs) * def->lb.smp_rgs_sz);
+ cpy->lb.smp_rgs = malloc(array_size_or_fail(sizeof(*cpy->lb.smp_rgs), def->lb.smp_rgs_sz));
if (!cpy->lb.smp_rgs)
goto error;
memcpy(cpy->lb.smp_rgs, def->lb.smp_rgs,
int duplicate_name = 0;
int err_code = 0;
- if ((resolv_line = malloc(sizeof(*resolv_line) * LINESIZE)) == NULL) {
+ if ((resolv_line = malloc(array_size_or_fail(sizeof(*resolv_line), LINESIZE))) == NULL) {
memprintf(errmsg, "out of memory.\n");
err_code |= ERR_ALERT | ERR_FATAL;
goto resolv_out;
/* initialize idle conns lists */
if (srv->max_idle_conns != 0) {
- srv->curr_idle_thr = ha_aligned_zalloc(64, global.nbthread * sizeof(*srv->curr_idle_thr));
+ srv->curr_idle_thr = ha_aligned_zalloc(64, array_size_or_fail(global.nbthread, sizeof(*srv->curr_idle_thr)));
if (!srv->curr_idle_thr) {
ha_alert("memory error during idle conn list init for %s/%s server\n",
srv->proxy->id, srv->id);
{
int i;
- srv->per_thr = ha_aligned_zalloc(64, global.nbthread * sizeof(*srv->per_thr));
- srv->per_tgrp = ha_aligned_zalloc(64, global.nbtgroups * sizeof(*srv->per_tgrp));
+ srv->per_thr = ha_aligned_zalloc(64, array_size_or_fail(global.nbthread, sizeof(*srv->per_thr)));
+ srv->per_tgrp = ha_aligned_zalloc(64, array_size_or_fail(global.nbtgroups, sizeof(*srv->per_tgrp)));
if (!srv->per_thr || !srv->per_tgrp)
return -1;
}
memset(&msghdr, 0, sizeof(msghdr));
- cmsgbuf = malloc(CMSG_SPACE(sizeof(int)) * MAX_SEND_FD);
+ cmsgbuf = malloc(array_size_or_fail(CMSG_SPACE(sizeof(int)), MAX_SEND_FD));
if (!cmsgbuf) {
ha_warning("Failed to allocate memory to send sockets\n");
goto out;
goto out;
}
- tmpbuf = malloc(fd_nb * (1 + MAXPATHLEN + 1 + IFNAMSIZ + sizeof(int)));
+ tmpbuf = malloc(array_size_or_fail(fd_nb, (1 + MAXPATHLEN + 1 + IFNAMSIZ + sizeof(int))));
if (tmpbuf == NULL) {
ha_warning("Failed to allocate memory while receiving sockets\n");
goto out;
}
- tmpfd = malloc(fd_nb * sizeof(int));
+ tmpfd = malloc(array_size_or_fail(fd_nb, sizeof(int)));
if (tmpfd == NULL) {
ha_warning("Failed to allocate memory while receiving sockets\n");
goto out;
/* copy the array of domain strings */
while (src->conf.acme.domains[n]) {
- r = my_realloc2(r, sizeof(char *) * (n + 2));
+ r = my_realloc2(r, array_size_or_fail(sizeof(char *), (n + 2)));
if (!r)
goto error;
/* copy the array of IP strings */
while (src->conf.acme.ips[n]) {
- r = my_realloc2(r, sizeof(char *) * (n + 2));
+ r = my_realloc2(r, array_size_or_fail(sizeof(char *), (n + 2)));
if (!r)
goto error;
do {
while (*e != ',' && *e != '\0')
e++;
- r = my_realloc2(r, sizeof(char *) * (n + 2));
+ r = my_realloc2(r, array_size_or_fail(sizeof(char *), (n + 2)));
if (!r) {
ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
err_code |= ERR_ALERT | ERR_ABORT;
int idx;
int new_size = passphrase_cache_size << 1;
- passphrase_randoms = my_realloc2(passphrase_randoms, sizeof(*passphrase_randoms) * (new_size));
+ passphrase_randoms = my_realloc2(passphrase_randoms, array_size_or_fail(sizeof(*passphrase_randoms), (new_size)));
if (!passphrase_randoms) {
ha_alert("ssl_sock_passwd_cb: passphrase randoms realloc failed");
passphrase_idx = -1;
if (passphrase_cache_size) {
passphrase_cache_size = new_size;
- passphrase_cache = my_realloc2(passphrase_cache, sizeof(*passphrase_cache) * passphrase_cache_size);
+ passphrase_cache = my_realloc2(passphrase_cache, array_size_or_fail(sizeof(*passphrase_cache), passphrase_cache_size));
if (!passphrase_cache) {
ha_alert("ssl_sock_passwd_cb: passphrase cache realloc failed");
passphrase_idx = -1;
goto out;
}
- line = malloc(sizeof(char) * LINESIZE);
+ line = malloc(array_size_or_fail(sizeof(char), LINESIZE));
if (!line) {
ha_warning("config: Can't load stats-file '%s': line alloc error.\n", global.stats_file);
goto out;
stat_cols_len[STATS_DOMAIN_PROXY] += ST_I_PX_MAX;
- stat_cols[STATS_DOMAIN_PROXY] = malloc(stat_cols_len[STATS_DOMAIN_PROXY] * sizeof(struct name_desc));
+ stat_cols[STATS_DOMAIN_PROXY] = malloc(array_size_or_fail(stat_cols_len[STATS_DOMAIN_PROXY], sizeof(struct name_desc)));
if (!stat_cols[STATS_DOMAIN_PROXY]) {
ha_alert("stats: cannot allocate all fields for proxy statistics\n");
err_code |= ERR_ALERT | ERR_FATAL;
size_t i = 0, offset;
int err_code = 0;
- stat_cols[STATS_DOMAIN_RESOLVERS] = malloc(stat_cols_len[STATS_DOMAIN_RESOLVERS] * sizeof(struct name_desc));
+ stat_cols[STATS_DOMAIN_RESOLVERS] = malloc(array_size_or_fail(stat_cols_len[STATS_DOMAIN_RESOLVERS], sizeof(struct name_desc)));
if (!stat_cols[STATS_DOMAIN_RESOLVERS]) {
ha_alert("stats: cannot allocate all fields for resolver statistics\n");
err_code |= ERR_ALERT | ERR_FATAL;
for (i = 0; i < STATS_DOMAIN_COUNT; ++i) {
const int domain = domains[i];
- stat_lines[domain] = malloc(stat_cols_len[domain] * sizeof(struct field));
+ stat_lines[domain] = malloc(array_size_or_fail(stat_cols_len[domain], sizeof(struct field)));
if (!stat_lines[domain])
return 0;
}
if (!global.tune.nb_stk_ctr)
return 0;
- pool_head_stk_ctr = create_pool("stk_ctr", sizeof(*((struct session*)0)->stkctr) * global.tune.nb_stk_ctr, MEM_F_SHARED);
+ pool_head_stk_ctr = create_pool("stk_ctr", array_size_or_fail(sizeof(*((struct session*)0)->stkctr), global.tune.nb_stk_ctr), MEM_F_SHARED);
if (!pool_head_stk_ctr) {
ha_alert("out of memory while creating the stick-counters pool.\n");
return ERR_ABORT;