From 446bd8a47694a368af687afd6f8bee0fe5590384 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Thu, 5 Jan 2017 08:17:17 +0000 Subject: [PATCH] Use calloc instead of malloc + memset(.., 0, ..) MFC after: 3 days --- contrib/bsnmp/snmpd/trans_lsock.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/contrib/bsnmp/snmpd/trans_lsock.c b/contrib/bsnmp/snmpd/trans_lsock.c index 5c656c856eb2..a390839f524c 100644 --- a/contrib/bsnmp/snmpd/trans_lsock.c +++ b/contrib/bsnmp/snmpd/trans_lsock.c @@ -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;