Use calloc instead of malloc + memset(.., 0, ..)

MFC after:	3 days
This commit is contained in:
Enji Cooper 2017-01-05 08:17:17 +00:00
parent 70157df618
commit 446bd8a476

View File

@ -146,16 +146,14 @@ lsock_open_port(u_char *name, size_t namelen, struct lsock_port **pp,
return (SNMP_ERR_BADVALUE);
}
if ((port = malloc(sizeof(*port))) == NULL)
if ((port = calloc(1, sizeof(*port))) == NULL)
return (SNMP_ERR_GENERR);
memset(port, 0, sizeof(*port));
if (!is_stream) {
if ((peer = malloc(sizeof(*peer))) == NULL) {
if ((peer = calloc(1, sizeof(*peer))) == NULL) {
free(port);
return (SNMP_ERR_GENERR);
}
memset(peer, 0, sizeof(*peer));
}
if ((port->name = malloc(namelen + 1)) == NULL) {
free(port);
@ -261,12 +259,11 @@ lsock_listen_input(int fd, void *udata)
struct lsock_port *p = udata;
struct lsock_peer *peer;
if ((peer = malloc(sizeof(*peer))) == NULL) {
if ((peer = calloc(1, sizeof(*peer))) == NULL) {
syslog(LOG_WARNING, "%s: peer malloc failed", p->name);
(void)close(accept(fd, NULL, NULL));
return;
}
memset(peer, 0, sizeof(*peer));
peer->port = p;