commit 62f852145bf61e3ed9b42f7a00cd7cd0b5ff8835 from: Stefan Sperling via: Thomas Adam date: Tue Aug 16 15:02:20 2022 UTC gotwebd: do not allocate address list heads separately, this is unnecessary ok millert@ commit - 717a78d4f87c3704afe34c77e211349932575d5b commit + 62f852145bf61e3ed9b42f7a00cd7cd0b5ff8835 blob - b58b1e7be0421dac9ff6c9717bacb59208ad1bbb blob + 2d740d8c68ee194fe07fbfdcd32adc917ba70b44 --- gotwebd/gotwebd.h +++ gotwebd/gotwebd.h @@ -252,7 +252,7 @@ TAILQ_HEAD(addresslist, address); struct server { TAILQ_ENTRY(server) entry; - struct addresslist *al; + struct addresslist al; char name[GOTWEBD_MAXTEXT]; @@ -294,7 +294,7 @@ enum sock_type { }; struct socket_conf { - struct addresslist *al; + struct addresslist al; char name[GOTWEBD_MAXTEXT]; char srv_name[GOTWEBD_MAXTEXT]; blob - c6ccf95e24f012d09dd077471386a59ca45b0d87 blob + 08b1a2f6f58ebda079361a779c7749acb5a02cf7 --- gotwebd/parse.y +++ gotwebd/parse.y @@ -226,7 +226,7 @@ server : SERVER STRING { new_srv = conf_new_server($2); if (new_srv->fcgi_socket) if (get_addrs(new_srv->fcgi_socket_bind, - new_srv->al, + &new_srv->al, new_srv->fcgi_socket_port) == -1) { yyerror("could not get tcp iface " "addrs"); @@ -251,7 +251,7 @@ server : SERVER STRING { free($2); } '{' optnl serveropts2 '}' { if (get_addrs(new_srv->fcgi_socket_bind, - new_srv->al, new_srv->fcgi_socket_port) == -1) { + &new_srv->al, new_srv->fcgi_socket_port) == -1) { yyerror("could not get tcp iface addrs"); YYERROR; } @@ -933,10 +933,7 @@ conf_new_server(const char *name) srv->unix_socket = 1; srv->fcgi_socket = gotwebd->fcgi_socket ? gotwebd->fcgi_socket : 0; - if ((srv->al = calloc(1, sizeof(*srv->al))) == NULL) - fatalx("%s: calloc", __func__); - - TAILQ_INIT(srv->al); + TAILQ_INIT(&srv->al); TAILQ_INSERT_TAIL(gotwebd->servers, srv, entry); gotwebd->server_cnt++; blob - f816f6ca9b9437b918e168e92de554c7f3df27af blob + 283e69d247baeb718f827dfff89f769ca1e9e125 --- gotwebd/sockets.c +++ gotwebd/sockets.c @@ -141,7 +141,7 @@ sockets_parse_sockets(struct gotwebd *env) TAILQ_FOREACH(sock, env->sockets, entry) { ipv4 = ipv6 = 0; - TAILQ_FOREACH(a, sock->conf.al, entry) { + TAILQ_FOREACH(a, &sock->conf.al, entry) { if (a->ss.ss_family == AF_INET) ipv4 = 1; if (a->ss.ss_family == AF_INET6) @@ -180,14 +180,12 @@ sockets_dup_new_socket(struct socket *p_sock, struct s n = snprintf(sock->conf.name, GOTWEBD_MAXTEXT, "%s_child", p_sock->conf.srv_name); if (n < 0 || (size_t)n >= GOTWEBD_MAXTEXT) { - free(p_sock->conf.al); free(p_sock); - free(sock->conf.al); free(sock); fatalx("%s: snprintf", __func__); } - TAILQ_FOREACH(a, p_sock->conf.al, entry) { + TAILQ_FOREACH(a, &p_sock->conf.al, entry) { if (a->ss.ss_family == AF_INET) continue; @@ -205,7 +203,7 @@ sockets_dup_new_socket(struct socket *p_sock, struct s } } - TAILQ_INSERT_TAIL(sock->conf.al, acp, entry); + TAILQ_INSERT_TAIL(&sock->conf.al, acp, entry); } } @@ -220,11 +218,7 @@ sockets_conf_new_socket(struct gotwebd *env, struct se if ((sock = calloc(1, sizeof(*sock))) == NULL) fatalx("%s: calloc", __func__); - if ((sock->conf.al = calloc(1, sizeof(*sock->conf.al))) == NULL) { - free(sock); - fatalx("%s: calloc", __func__); - } - TAILQ_INIT(sock->conf.al); + TAILQ_INIT(&sock->conf.al); sock->conf.parent_id = 0; sock->conf.id = id; @@ -238,7 +232,6 @@ sockets_conf_new_socket(struct gotwebd *env, struct se srv->unix_socket_name, sizeof(sock->conf.unix_socket_name)) >= sizeof(sock->conf.unix_socket_name)) { - free(sock->conf.al); free(sock); fatalx("%s: strlcpy", __func__); } @@ -253,21 +246,18 @@ sockets_conf_new_socket(struct gotwebd *env, struct se n = snprintf(sock->conf.name, GOTWEBD_MAXTEXT, "%s_parent", srv->name); if (n < 0 || (size_t)n >= GOTWEBD_MAXTEXT) { - free(sock->conf.al); free(sock); fatalx("%s: snprintf", __func__); } if (strlcpy(sock->conf.srv_name, srv->name, sizeof(sock->conf.srv_name)) >= sizeof(sock->conf.srv_name)) { - free(sock->conf.al); free(sock); fatalx("%s: strlcpy", __func__); } - TAILQ_FOREACH(a, srv->al, entry) { + TAILQ_FOREACH(a, &srv->al, entry) { if ((acp = calloc(1, sizeof(*acp))) == NULL) { - free(sock->conf.al); free(sock); fatal("%s: calloc", __func__); } @@ -283,7 +273,7 @@ sockets_conf_new_socket(struct gotwebd *env, struct se } } - TAILQ_INSERT_TAIL(sock->conf.al, acp, entry); + TAILQ_INSERT_TAIL(&sock->conf.al, acp, entry); } done: return (sock); @@ -437,7 +427,7 @@ sockets_privinit(struct gotwebd *env, struct socket *s if (sock->conf.type == FCGI) { log_debug("%s: initializing fcgi socket for %s", __func__, sock->conf.name); - sock->fd = sockets_create_socket(sock->conf.al, + sock->fd = sockets_create_socket(&sock->conf.al, sock->conf.fcgi_socket_port); if (sock->fd == -1) { log_warnx("%s: create unix socket failed", __func__);